package com.hykj.dao;
import com.hykj.entity.Role;
import com.hykj.entity.UserInfo;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* @author: Mr.Chen
* @program: management
* @create: 2019-10-15 16:42
* @description: UserDao
**/
@Repository("userDao")
public interface UserDao {
@Select("select * from users")
List<UserInfo> findAll();
@Insert("insert into users(email,username,password,phoneNum,status) values(#{email},#{username},#{password},#{phoneNum},#{status})")
void save(UserInfo user);
@Select("select * from users where username=#{username}")
@Results({
@Result(id = true,property = "id",column = "id"),
@Result(property = "email",column = "email"),
@Result(property = "username",column = "username"),
@Result(property = "password",column = "password"),
@Result(property = "phoneNum",column = "phoneNum"),
@Result(property = "status",column = "status"),
@Result(property = "roles",column = "id",javaType = java.util.List.class,many = @Many(select = "com.hykj.dao.RolesDao.findByUserId"))
})
UserInfo findByUsername(String userName);
@Select("select * from users where id = #{id}")
@Results({
@Result(id = true,property = "id",column = "id"),
@Result(property = "email",column = "email"),
@Result(property = "username",column = "username"),
@Result(property = "password",column = "password"),
@Result(property = "phoneNum",column = "phoneNum"),
@Result(property = "status",column = "status"),
@Result(property = "roles",column = "id",javaType = java.util.List.class,many = @Many(select = "com.hykj.dao.RolesDao.findByUserId"))
})
UserInfo findById(int id);
@Select("SELECT * FROM role WHERE id NOT IN(SELECT roleId FROM users_role WHERE userId=#{id})")
List<Role> findOtherRolers(int id);
@Insert("Insert into users_role values(#{userId},#{id})")
void addRoleToUser(@Param("userId") int userId,@Param("id") int id);
}
|
|