A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 335778654 初级黑马   /  2019-10-16 15:30  /  821 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

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);
}


0 个回复

您需要登录后才可以回帖 登录 | 加入黑马