MyBtis的处理流程图
1、在resources文件夹下创建mappers文件夹![请添加图片描述](https://i-blog.csdnimg.cn/blog_migrate/50ba05eac4765ecc612cd6eebd9fdd79.png)
2、在application.yml配置文件中配置mapper文件夹
#mybatisPlus相关配置
mybatis-plus:
mapper-locations: classpath:mappers/*.xml
3、在mapper中添加登录的方法
4、在mappers文件夹中创建UserMapper.xml文件![请添加图片描述](https://i-blog.csdnimg.cn/blog_migrate/25d5959fd3d0306f1fe8ce40cc17fdcc.png)
通过namespace指定DAO接口的路径
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="demo.dao.UserDAO">
</mapper>
5、维护login方法的sql语句
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="demo.dao.UserDAO">
<select id="login" resultType="demo.entity.User">
select * from t_user where user_name=#{userName} and passwd=#{passwd}
</select>
</mapper>
6、在controller中测试
@RequestMapping("/login")
public String login(String userName, String passwd){
User u = dao.login(userName, passwd);
if(u != null){
return "登录成功";
} else {
return "登录失败";
}
}