第一步:需要在Mapper层实现的接口
List<User> login(@Param("param") Map map);
第二步:需要在XML文件中写SQL语句
- <select id="login" resultMap="BaseResultMap">
- SELECT * from user
- wherer username = ${param.username} and password = ${param.password}
- </select>
第三步:需要在Service中实现接口
- boolean login(User user, HttpSession session);
第四步:需要在ServiceImpl中实现
@Override
public boolean login(User user, HttpSession session) {
Map<String, Object> map = new HashMap<>();
map.put("username",user.getUsername());
map.put("password", user.getPassword());
List<User> users = this.selectByMap(map);
//如果用户存在,放入session域
if(users.size()>0