SpringBoot case - basic login function

According to the page prototype, clarify the requirements

page prototype

need

Enter the correct account password to enter 

Read the interface documentation

The interface document link is as follows:

https://hkm-web.oss-cn-beijing.aliyuncs.com/%E6%8E%A5%E5%8F%A3%E6%96%87%E6%A1%A3

Idea analysis

After the backend receives the user name and password passed by the frontend, it performs a query in the database. If the existence of the user information is found, the login is allowed, otherwise, the login is refused. The result of the query is an Emp object type of data

Realization of interface functions

Control layer (Controller class)

The specific key codes are as follows:

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.success() : Result.error("用户名或密码错误");
    }
}

Business layer (Service class)

The specific key codes are as follows:

business class

Emp Login(Emp emp);

business realization class

    @Override
    public Emp Login(Emp emp) {
        Emp empResult = empMapper.getByUsernameAndPassword(emp);
        return empResult;
    }

Persistence layer (Mapper class)

The specific key codes are as follows:

    /**
     * 根据用户名和密码查询用户信息
     *
     * @param emp
     * @return
     */
    @Select("select * from emp where username=#{username} and password=#{password}")
    Emp getByUsernameAndPassword(Emp emp);

interface test

Use postman for interface testing, the specific access path and parameters are as follows:

The result of the operation is as follows:

 

Front-end and back-end joint debugging

Login failed

 

login successful

 

Guess you like

Origin blog.csdn.net/weixin_64939936/article/details/132480175