一,目录结构
二,创建用户实体类
与数据库内容对应
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