javaEEday10-tlias管理系统-基础登录功能
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package com.inmind.controller;
|
||||
|
||||
import com.inmind.pojo.Emp;
|
||||
import com.inmind.pojo.Result;
|
||||
import com.inmind.service.EmpService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@Slf4j
|
||||
public class LoginController {
|
||||
|
||||
@Autowired
|
||||
private EmpService empService;
|
||||
|
||||
@PostMapping("/login")
|
||||
public Result login(@RequestBody Emp emp){
|
||||
log.info("登录操作:{}",emp);
|
||||
//调用员工的业务层,根据用户名与密码查询员工是否存在,表示登录是否成功
|
||||
Emp e = empService.login(emp);
|
||||
return e ==null?Result.error("用户名或密码错误"):Result.success();
|
||||
}
|
||||
}
|
||||
@@ -45,4 +45,6 @@ public interface EmpMapper {
|
||||
Emp getEmpById(Integer id);
|
||||
|
||||
void updateEmp(Emp emp);
|
||||
@Select("select * from emp where username = #{username} and password = #{password};")
|
||||
Emp getEmpByUserAndPwd(Emp emp);
|
||||
}
|
||||
|
||||
@@ -21,4 +21,7 @@ public interface EmpService {
|
||||
|
||||
//修改员工信息
|
||||
void updateEmp(Emp emp);
|
||||
|
||||
//员工登录
|
||||
Emp login(Emp emp);
|
||||
}
|
||||
|
||||
@@ -87,4 +87,17 @@ public class EmpServiceImpl implements EmpService {
|
||||
emp.setUpdateTime(LocalDateTime.now());
|
||||
empMapper.updateEmp(emp);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param emp 只需要username和password的数据,用来查询员工
|
||||
* @return 查询到的完整的员工信息
|
||||
*/
|
||||
@Override
|
||||
public Emp login(Emp emp) {
|
||||
//调用empMapper查询员工信息
|
||||
/*Emp e = empMapper.getEmpByUserAndPwd(emp);
|
||||
return e;*/
|
||||
return empMapper.getEmpByUserAndPwd(emp);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user