添加角色相关的接口,用户信息添加角色信息

This commit is contained in:
648540858
2021-08-10 15:42:15 +08:00
parent dbc525e8fb
commit 9e8cab609d
29 changed files with 598 additions and 134 deletions

View File

@@ -0,0 +1,35 @@
package com.genersoft.iot.vmp.storager.dao;
import com.genersoft.iot.vmp.storager.dao.dto.Role;
import com.genersoft.iot.vmp.storager.dao.dto.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import java.util.List;
@Mapper
@Repository
public interface RoleMapper {
@Insert("INSERT INTO role (name, authority, createTime, updateTime) VALUES" +
"('${name}', '${authority}', '${createTime}', '${updateTime}')")
int add(Role role);
@Update(value = {" <script>" +
"UPDATE role " +
"SET updateTime='${updateTime}' " +
"<if test=\"name != null\">, name='${name}'</if>" +
"<if test=\"authority != null\">, authority='${authority}'</if>" +
"WHERE id != 1 and id=#{id}" +
" </script>"})
int update(Role role);
@Delete("DELETE FROM role WHERE id != 1 and id=#{id}")
int delete(int id);
@Select("select * FROM role WHERE id=#{id}")
Role selectById(int id);
@Select("select * FROM role")
List<Role> selectAll();
}

View File

@@ -10,32 +10,42 @@ import java.util.List;
@Repository
public interface UserMapper {
@Insert("INSERT INTO user (username, password, roleId, create_time, update_time) VALUES" +
"('${username}', '${password}', '${roleId}', '${createTime}', '${updateTime}')")
@Insert("INSERT INTO user (username, password, roleId, createTime, updateTime) VALUES" +
"('${username}', '${password}', '${role.id}', '${createTime}', '${updateTime}')")
int add(User user);
@Update(value = {" <script>" +
"UPDATE user " +
"SET update_time='${updateTime}' " +
"<if test=\"roleId != null\">, roleId='${roleId}'</if>" +
"SET updateTime='${updateTime}' " +
"<if test=\"role != null\">, roleId='${role.id}'</if>" +
"<if test=\"password != null\">, password='${password}'</if>" +
"<if test=\"username != null\">, username='${username}'</if>" +
"WHERE id=#{id}" +
" </script>"})
int update(User user);
@Delete("DELETE FROM user WHERE id=#{id}")
@Delete("DELETE FROM user WHERE id != 1 and id=#{id}")
int delete(int id);
@Select("select * FROM user WHERE username=#{username} AND password=#{password}")
@Select("select user.*, role.id roleID, role.name roleName, role.authority roleAuthority , role.createTime roleCreateTime , role.updateTime roleUpdateTime FROM user, role WHERE user.roleId=role.id and user.username=#{username} AND user.password=#{password}")
@Results(id = "roleMap", value = {
@Result(column = "roleID", property = "role.id"),
@Result(column = "roleName", property = "role.name"),
@Result(column = "roleAuthority", property = "role.authority"),
@Result(column = "roleCreateTime", property = "role.createTime"),
@Result(column = "roleUpdateTime", property = "role.updateTime")
})
User select(String username, String password);
@Select("select * FROM user WHERE id=#{id}")
@Select("select user.*, role.id roleID, role.name roleName, role.authority roleAuthority, role.createTime roleCreateTime , role.updateTime roleUpdateTime FROM user, role WHERE user.roleId=role.id and user.id=#{id}")
@ResultMap(value="roleMap")
User selectById(int id);
@Select("select * FROM user WHERE username=#{username}")
@Select("select user.*, role.id roleID, role.name roleName, role.authority roleAuthority, role.createTime roleCreateTime , role.updateTime roleUpdateTime FROM user, role WHERE user.roleId=role.id and username=#{username}")
@ResultMap(value="roleMap")
User getUserByUsername(String username);
@Select("select * FROM user")
@Select("select user.*, role.id roleID, role.name roleName, role.authority roleAuthority, role.createTime roleCreateTime , role.updateTime roleUpdateTime FROM user, role WHERE user.roleId=role.id")
@ResultMap(value="roleMap")
List<User> selectAll();
}

View File

@@ -0,0 +1,50 @@
package com.genersoft.iot.vmp.storager.dao.dto;
public class Role {
private int id;
private String name;
private String authority;
private String createTime;
private String updateTime;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAuthority() {
return authority;
}
public void setAuthority(String authority) {
this.authority = authority;
}
public String getCreateTime() {
return createTime;
}
public void setCreateTime(String createTime) {
this.createTime = createTime;
}
public String getUpdateTime() {
return updateTime;
}
public void setUpdateTime(String updateTime) {
this.updateTime = updateTime;
}
}

View File

@@ -7,7 +7,7 @@ public class User {
private String password;
private String createTime;
private String updateTime;
private int roleId;
private Role role;
public int getId() {
return id;
@@ -41,14 +41,6 @@ public class User {
this.createTime = createTime;
}
public int getRoleId() {
return roleId;
}
public void setRoleId(int roleId) {
this.roleId = roleId;
}
public String getUpdateTime() {
return updateTime;
}
@@ -56,4 +48,12 @@ public class User {
public void setUpdateTime(String updateTime) {
this.updateTime = updateTime;
}
public Role getRole() {
return role;
}
public void setRole(Role role) {
this.role = role;
}
}