结组作业6
今天写的是用户登录和注册时使用到的与数据库连接的方法和各层的代码
1 package org.test.tongyuzhe.Mapper; 2 3 import org.apache.ibatis.annotations.Insert; 4 import org.apache.ibatis.annotations.Mapper; 5 import org.apache.ibatis.annotations.Select; 6 import org.test.tongyuzhe.Pojo.User; 7 8 @Mapper 9 public interface UserMapper { 10 @Select("select * from user where username = #{name}") 11 User findByUserName(String name); 12 @Insert("insert into user(username,password,role,child_id)" + 13 "values(#{username},#{md5Password},#{role},#{child_id})") 14 void register(String username, String md5Password,int role,int child_id); 15 16 17 }
1 package org.test.tongyuzhe.Service; 2 3 import org.springframework.beans.factory.annotation.Autowired; 4 import org.springframework.stereotype.Service; 5 import org.test.tongyuzhe.Mapper.UserMapper; 6 import org.test.tongyuzhe.Pojo.User; 7 import org.test.tongyuzhe.utils.Md5Util; 8 9 @Service 10 public class UserService { 11 12 @Autowired 13 private UserMapper userMapper; 14 public User findByUserName(String name) { 15 return userMapper.findByUserName(name); 16 } 17 public void register(User user) { 18 //加密 19 String md5Password = Md5Util.getMD5String(user.getPassword()); 20 //添加 21 userMapper.register(user.getUsername(),md5Password,user.getRole(),user.getChildId()); 22 } 23 24 }
在进行登录时,超哥还使用了md5加密,同时使用了jwt令牌,提高软件的安全性