一,目录结构

二,创建用户实体类
与数据库内容对应
package com.example.springbootsecurityonetable.model;
import lombok.Data;
/**
* @Author: xc
* @Date: 2018/11/18 17:03
* @Description:
**/
@Data
public class MyUser {
private String id;
private String username;
private String password;
private String roles;
}
三,UserMapper操作数据库
package com.example.springbootsecurityonetable.mapper;
import com.example.springbootsecurityonetable.model.MyUser;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
@Repository
@Mapper
public interface UserMapper {
@Insert("insert into user(username, password, roles) values(#{username}, #{password}, #{roles})")
boolean insert(MyUser user);
@Select("SELECT * FROM user WHERE username=#{name}")
MyUser findByUserName(String name);
}
四,服务类
- 接口
package com.example.springbootsecurityonetable.service; import com.example.springbootsecurityonetable.model.MyUser; /** * @Author: xc * @Date: 2018/11/18 17:12 * @Description: **/ public interface UserService { boolean insert(MyUser user); MyUser findByUserName(String name); } - 实现类
package com.example.springbootsecurityonetable.service.Impl;
import com.example.springbootsecurityonetable.mapper.UserMapper;
import com.example.springbootsecurityonetable.model.MyUser;
import com.example.springbootsecurityonetable.role.Role;
import com.example.springbootsecurityonetable.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* @Author: xc
* @Date: 2018/11/18 17:15
* @Description:
**/
@Service
public class UserServiceImpl implements UserService

本文详细介绍了使用SpringBoot、Security和Mybatis进行注解方式的集成和配置过程,包括目录结构、用户实体类创建、数据库操作、服务类与UserDetails接口实现、Spring Security的设置以及控制器和配置文件的详细配置。特别强调了Spring Security 5.0中密码编码处理的重要性。
最低0.47元/天 解锁文章
2836

被折叠的 条评论
为什么被折叠?



