完成根据用户获取用户身份认证User对象的 dao,service编写

This commit is contained in:
winLsy
2017-12-17 21:55:29 +08:00
parent 02f7a2fd11
commit 71e21beba1
4 changed files with 55 additions and 5 deletions
+5 -5
View File
@@ -22,11 +22,11 @@
<artifactId>boot-starter-ssm</artifactId>
<version>${micro.fast.version}</version>
</dependency>
<!--<dependency>-->
<!--<groupId>com.micro.fast</groupId>-->
<!--<artifactId>boot-starter-security-browser</artifactId>-->
<!--<version>${micro.fast.version}</version>-->
<!--</dependency>-->
<dependency>
<groupId>com.micro.fast</groupId>
<artifactId>boot-starter-security-browser</artifactId>
<version>${micro.fast.version}</version>
</dependency>
<!--监控-->
<dependency>
<groupId>org.springframework.boot</groupId>
@@ -2,11 +2,16 @@ package com.micro.fast.upms.dao;
import com.micro.fast.upms.pojo.UpmsUser;
/**
* @author lsy
*/
public interface UpmsUserMapper {
int deleteByPrimaryKey(Integer id);
int insert(UpmsUser record);
UpmsUser selectByUsername(String username);
int insertSelective(UpmsUser record);
UpmsUser selectByPrimaryKey(Integer id);
@@ -0,0 +1,39 @@
package com.micro.fast.upms.service.impl;
import com.micro.fast.security.browser.service.UserService;
import com.micro.fast.upms.dao.UpmsUserMapper;
import com.micro.fast.upms.pojo.UpmsUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.stereotype.Service;
/**
* 后台权限管理系统用户操作接口实现类
* @author lsy
*/
@Service("userServiceImpl")
public class UpmsUserServiceImpl implements UserService{
@Autowired
private UpmsUserMapper upmsUserMapper;
@Override
public User getUserByUsername(String username) {
UpmsUser upmsUser = upmsUserMapper.selectByUsername(username);
//将根据用户名查询出来的用户信息填入springSecurity的User对象中,默认是admin权限 todo 需要进行完善
User user = new User(username,upmsUser.getPassword(), AuthorityUtils.commaSeparatedStringToAuthorityList("admin"));
return user;
}
//todo 添加用户
public int addUser(String username,String password){
UpmsUser upmsUser = new UpmsUser();
upmsUser.setUsername(username);
upmsUser.setPassword(password);
int insert = upmsUserMapper.insert(upmsUser);
return insert;
}
}
@@ -25,6 +25,12 @@
from upms_user
where id = #{id,jdbcType=INTEGER}
</select>
<select id="selectByUsername" resultType="com.micro.fast.upms.pojo.UpmsUser">
SELECT
<include refid="Base_Column_List"/>
FROM upms_user
WHERE username = #{username}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from upms_user
where id = #{id,jdbcType=INTEGER}