1.创建springboot项目,配置。properties配置文件,
2. 配置@MapperScan(basePackages = "com.liuboss.vhr.mapper") 注解,使springboot可以扫描到mapper实体类。
3.@ComponentScan("com.jiawa") 为springboot启动类的扫描注解,用于更换启动类位置。
4. /*配置类*/ @Configuration, 将配置类注入进springboot
5.springboot项目报错不一定鼎时代吗错误,依赖假的过多,版本冲突。删除多余依赖,修改版本。
6.代码实现-自动生成model和mapper接口
实现集成Security安全框架。
- @Service
- public class HrService implements UserDetailsService {
- @Autowired
- HrMapper hrMapper;
- @Override
- public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
- Hr hr = hrMapper.loadUserByUsername(username);
- if (hr==null){
- throw new UsernameNotFoundException("用户不存在!");
- }
- return hr;
- }
- }
集成配置类
- /*配置类*/
- @Configuration
- public class SecurityConfig extends WebSecurityConfigurerAdapter {
- @Autowired
- HrService hrService;
-
- @Bean
- PasswordEncoder passwordEncoder(){
- return new BCryptPasswordEncoder();
- }
-
- @Override
- protected void configure(AuthenticationManagerBuilder auth) throws Exception {
- auth.userDetailsService(hrService);
- }
- }
测试接口进行测试
- @RestController
- public class Hello {
- @GetMapping("/hello")
- public String hello(){
- return "hello";
- }
- }
输入密码登陆成功