my-csc-config-file.git 5 anni fa
parent
commit
ebb9ae6573

+ 11 - 6
pom.xml

@@ -67,12 +67,6 @@
67 67
             <artifactId>spring-boot-starter-jdbc</artifactId>
68 68
         </dependency>
69 69
 
70
-        <!--mybatis-spring-boot-->
71
-        <dependency>
72
-            <groupId>org.mybatis.spring.boot</groupId>
73
-            <artifactId>mybatis-spring-boot-starter</artifactId>
74
-        </dependency>
75
-
76 70
         <!--redis-->
77 71
         <dependency>
78 72
             <groupId>org.springframework.boot</groupId>
@@ -103,6 +97,17 @@
103 97
             <artifactId>fastjson</artifactId>
104 98
             <version>1.2.41</version>
105 99
         </dependency>
100
+        <!-- mybatisplus与springboot整合 -->
101
+        <dependency>
102
+            <groupId>com.baomidou</groupId>
103
+            <artifactId>mybatis-plus-boot-starter</artifactId>
104
+        </dependency>
105
+        <!-- springboot整合mybatis(核心就这一个) -->
106
+        <!-- 注意顺序,这个一定要放在最下面 -->
107
+        <dependency>
108
+            <groupId>org.mybatis.spring.boot</groupId>
109
+            <artifactId>mybatis-spring-boot-starter</artifactId>
110
+        </dependency>
106 111
 
107 112
     </dependencies>
108 113
 

+ 3 - 3
src/main/java/com/unissoft/controller/UserController.java

@@ -2,7 +2,7 @@ package com.unissoft.controller;
2 2
 
3 3
 import com.alibaba.fastjson.JSON;
4 4
 import com.alibaba.fastjson.JSONObject;
5
-import com.unissoft.model.UserModel;
5
+import com.unissoft.model.SysUser;
6 6
 import org.springframework.beans.factory.annotation.Autowired;
7 7
 import org.springframework.security.core.Authentication;
8 8
 import org.springframework.security.core.context.SecurityContext;
@@ -86,8 +86,8 @@ public class UserController {
86 86
         JSONObject jsonObject = JSON.parseObject(claims);
87 87
         Map<String, String> jsonMap = JSONObject.toJavaObject(jsonObject, Map.class);
88 88
         JSONObject user = JSON.parseObject(jsonMap.get("user_name"));
89
-        UserModel userModel = JSONObject.toJavaObject(user, UserModel.class);
90
-        System.out.println(userModel);
89
+        SysUser SysUser = JSONObject.toJavaObject(user, SysUser.class);
90
+        System.out.println(SysUser);
91 91
         return ResultView.success(decode);
92 92
     }
93 93
 }

+ 4 - 4
src/main/java/com/unissoft/mapper/PublicMapper.java

@@ -1,8 +1,8 @@
1 1
 package com.unissoft.mapper;
2 2
 
3
-import com.unissoft.model.OauthClientDetailsModel;
4
-import com.unissoft.model.UserModel;
5 3
 import com.unissoft.dto.BaseDto;
4
+import com.unissoft.model.OauthClientDetailsModel;
5
+import com.unissoft.model.SysUser;
6 6
 
7 7
 import java.util.List;
8 8
 
@@ -11,9 +11,9 @@ import java.util.List;
11 11
  */
12 12
 public interface PublicMapper {
13 13
 
14
-    UserModel getUserByName(String name);
14
+    SysUser getUserByName(String name);
15 15
 
16
-    List<BaseDto> getRoleByUserId(Long userId);
16
+    List<BaseDto> getRoleByUserId(int userId);
17 17
 
18 18
     OauthClientDetailsModel getOauthClientDetailsByClientId(String clientId);
19 19
 

+ 282 - 0
src/main/java/com/unissoft/model/SysUser.java

@@ -0,0 +1,282 @@
1
+package com.unissoft.model;
2
+
3
+
4
+
5
+import com.baomidou.mybatisplus.annotation.IdType;
6
+import com.baomidou.mybatisplus.annotation.TableField;
7
+import com.baomidou.mybatisplus.annotation.TableId;
8
+import com.baomidou.mybatisplus.annotation.TableName;
9
+
10
+import java.io.Serializable;
11
+import java.util.Date;
12
+
13
+/**
14
+ * <p>
15
+ * 用户表
16
+ * </p>
17
+ *
18
+ * @author wsm
19
+ * @since 2020-11-25
20
+ */
21
+@TableName("sys_user")
22
+public class SysUser implements Serializable {
23
+
24
+    private static final long serialVersionUID = 1L;
25
+
26
+    @TableId(value = "u_id", type = IdType.AUTO)
27
+    private Integer uId;
28
+    /**
29
+     * 用户名
30
+     */
31
+    @TableField("u_name")
32
+    private String uName;
33
+    /**
34
+     * 昵称
35
+     */
36
+    @TableField("u_nickname")
37
+    private String uNickname;
38
+    /**
39
+     * 密码
40
+     */
41
+    @TableField("u_password")
42
+    private String uPassword;
43
+    /**
44
+     * 头像
45
+     */
46
+    @TableField("u_photo")
47
+    private String uPhoto;
48
+    /**
49
+     * 性别(0女,1男)
50
+     */
51
+    @TableField("u_sex")
52
+    private Integer uSex;
53
+    /**
54
+     * 生日
55
+     */
56
+    @TableField("u_birthday")
57
+    private Date uBirthday;
58
+    /**
59
+     * 手机号
60
+     */
61
+    @TableField("u_phone")
62
+    private String uPhone;
63
+    /**
64
+     * 邮箱
65
+     */
66
+    @TableField("u_mail")
67
+    private String uMail;
68
+    /**
69
+     * 地址
70
+     */
71
+    @TableField("u_address")
72
+    private String uAddress;
73
+    /**
74
+     * 个人说明
75
+     */
76
+    @TableField("u_explain")
77
+    private String uExplain;
78
+    /**
79
+     * 用户来源
80
+     */
81
+    @TableField("u_user_source")
82
+    private Integer uUserSource;
83
+    /**
84
+     * 用户状态(1:正常,2:异常,3:禁用)
85
+     */
86
+    @TableField("u_status")
87
+    private Integer uStatus;
88
+    /**
89
+     * 创建人
90
+     */
91
+    @TableField("u_create_by")
92
+    private String uCreateBy;
93
+    /**
94
+     * 创建时间
95
+     */
96
+    @TableField("u_create_time")
97
+    private Date uCreateTime;
98
+    /**
99
+     * 更新人
100
+     */
101
+    @TableField("u_update_by")
102
+    private String uUpdateBy;
103
+    /**
104
+     * 更新时间
105
+     */
106
+    @TableField("u_update_time")
107
+    private Date uUpdateTime;
108
+    /**
109
+     * 备注
110
+     */
111
+    @TableField("u_remark")
112
+    private String uRemark;
113
+
114
+
115
+    public Integer getuId() {
116
+        return uId;
117
+    }
118
+
119
+    public void setuId(Integer uId) {
120
+        this.uId = uId;
121
+    }
122
+
123
+    public String getuName() {
124
+        return uName;
125
+    }
126
+
127
+    public void setuName(String uName) {
128
+        this.uName = uName;
129
+    }
130
+
131
+    public String getuNickname() {
132
+        return uNickname;
133
+    }
134
+
135
+    public void setuNickname(String uNickname) {
136
+        this.uNickname = uNickname;
137
+    }
138
+
139
+    public String getuPassword() {
140
+        return uPassword;
141
+    }
142
+
143
+    public void setuPassword(String uPassword) {
144
+        this.uPassword = uPassword;
145
+    }
146
+
147
+    public String getuPhoto() {
148
+        return uPhoto;
149
+    }
150
+
151
+    public void setuPhoto(String uPhoto) {
152
+        this.uPhoto = uPhoto;
153
+    }
154
+
155
+    public Integer getuSex() {
156
+        return uSex;
157
+    }
158
+
159
+    public void setuSex(Integer uSex) {
160
+        this.uSex = uSex;
161
+    }
162
+
163
+    public Date getuBirthday() {
164
+        return uBirthday;
165
+    }
166
+
167
+    public void setuBirthday(Date uBirthday) {
168
+        this.uBirthday = uBirthday;
169
+    }
170
+
171
+    public String getuPhone() {
172
+        return uPhone;
173
+    }
174
+
175
+    public void setuPhone(String uPhone) {
176
+        this.uPhone = uPhone;
177
+    }
178
+
179
+    public String getuMail() {
180
+        return uMail;
181
+    }
182
+
183
+    public void setuMail(String uMail) {
184
+        this.uMail = uMail;
185
+    }
186
+
187
+    public String getuAddress() {
188
+        return uAddress;
189
+    }
190
+
191
+    public void setuAddress(String uAddress) {
192
+        this.uAddress = uAddress;
193
+    }
194
+
195
+    public String getuExplain() {
196
+        return uExplain;
197
+    }
198
+
199
+    public void setuExplain(String uExplain) {
200
+        this.uExplain = uExplain;
201
+    }
202
+
203
+    public Integer getuUserSource() {
204
+        return uUserSource;
205
+    }
206
+
207
+    public void setuUserSource(Integer uUserSource) {
208
+        this.uUserSource = uUserSource;
209
+    }
210
+
211
+    public Integer getuStatus() {
212
+        return uStatus;
213
+    }
214
+
215
+    public void setuStatus(Integer uStatus) {
216
+        this.uStatus = uStatus;
217
+    }
218
+
219
+    public String getuCreateBy() {
220
+        return uCreateBy;
221
+    }
222
+
223
+    public void setuCreateBy(String uCreateBy) {
224
+        this.uCreateBy = uCreateBy;
225
+    }
226
+
227
+    public Date getuCreateTime() {
228
+        return uCreateTime;
229
+    }
230
+
231
+    public void setuCreateTime(Date uCreateTime) {
232
+        this.uCreateTime = uCreateTime;
233
+    }
234
+
235
+    public String getuUpdateBy() {
236
+        return uUpdateBy;
237
+    }
238
+
239
+    public void setuUpdateBy(String uUpdateBy) {
240
+        this.uUpdateBy = uUpdateBy;
241
+    }
242
+
243
+    public Date getuUpdateTime() {
244
+        return uUpdateTime;
245
+    }
246
+
247
+    public void setuUpdateTime(Date uUpdateTime) {
248
+        this.uUpdateTime = uUpdateTime;
249
+    }
250
+
251
+    public String getuRemark() {
252
+        return uRemark;
253
+    }
254
+
255
+    public void setuRemark(String uRemark) {
256
+        this.uRemark = uRemark;
257
+    }
258
+
259
+    @Override
260
+    public String toString() {
261
+        return "SysUser{" +
262
+        ", uId=" + uId +
263
+        ", uName=" + uName +
264
+        ", uNickname=" + uNickname +
265
+        ", uPassword=" + uPassword +
266
+        ", uPhoto=" + uPhoto +
267
+        ", uSex=" + uSex +
268
+        ", uBirthday=" + uBirthday +
269
+        ", uPhone=" + uPhone +
270
+        ", uMail=" + uMail +
271
+        ", uAddress=" + uAddress +
272
+        ", uExplain=" + uExplain +
273
+        ", uUserSource=" + uUserSource +
274
+        ", uStatus=" + uStatus +
275
+        ", uCreateBy=" + uCreateBy +
276
+        ", uCreateTime=" + uCreateTime +
277
+        ", uUpdateBy=" + uUpdateBy +
278
+        ", uUpdateTime=" + uUpdateTime +
279
+        ", uRemark=" + uRemark +
280
+        "}";
281
+    }
282
+}

+ 0 - 255
src/main/java/com/unissoft/model/UserModel.java

@@ -1,255 +0,0 @@
1
-package com.unissoft.model;
2
-
3
-
4
-import java.io.Serializable;
5
-import java.util.Date;
6
-
7
-/**
8
- * 文件描述:用户表
9
- *
10
- * @author tongxi.xia
11
- * @date 2020年11月17日 15:16
12
- */
13
-public class UserModel implements Serializable {
14
-
15
-    private static final long serialVersionUID = 1L;
16
-
17
-    private Long id;
18
-    /**
19
-     * 用户名
20
-     */
21
-    private String name;
22
-    /**
23
-     * 昵称
24
-     */
25
-    private String nickname;
26
-    /**
27
-     * 密码
28
-     */
29
-    private String password;
30
-    /**
31
-     * 头像
32
-     */
33
-    private String photo;
34
-    /**
35
-     * 性别(0女,1男)
36
-     */
37
-    private Integer sex;
38
-    /**
39
-     * 生日
40
-     */
41
-    private Date birthday;
42
-    /**
43
-     * 手机号
44
-     */
45
-    private String phone;
46
-    /**
47
-     * 邮箱
48
-     */
49
-    private String mail;
50
-    /**
51
-     * 地址
52
-     */
53
-    private String address;
54
-    /**
55
-     * 个人说明
56
-     */
57
-    private String explain;
58
-    /**
59
-     * 用户来源
60
-     */
61
-    private Integer userSource;
62
-    /**
63
-     * 用户状态(1:正常,2:异常,3:禁用)
64
-     */
65
-    private Integer status;
66
-    /**
67
-     * 创建人
68
-     */
69
-    private String createBy;
70
-    /**
71
-     * 创建时间
72
-     */
73
-    private Date createTime;
74
-    /**
75
-     * 更新人
76
-     */
77
-    private String updateBy;
78
-    /**
79
-     * 更新时间
80
-     */
81
-    private Date updateTime;
82
-    /**
83
-     * 备注
84
-     */
85
-    private String remark;
86
-
87
-
88
-    public Long getId() {
89
-        return id;
90
-    }
91
-
92
-    public void setId(Long id) {
93
-        this.id = id;
94
-    }
95
-
96
-    public String getName() {
97
-        return name;
98
-    }
99
-
100
-    public void setName(String name) {
101
-        this.name = name;
102
-    }
103
-
104
-    public String getNickname() {
105
-        return nickname;
106
-    }
107
-
108
-    public void setNickname(String nickname) {
109
-        this.nickname = nickname;
110
-    }
111
-
112
-    public String getPassword() {
113
-        return password;
114
-    }
115
-
116
-    public void setPassword(String password) {
117
-        this.password = password;
118
-    }
119
-
120
-    public String getPhoto() {
121
-        return photo;
122
-    }
123
-
124
-    public void setPhoto(String photo) {
125
-        this.photo = photo;
126
-    }
127
-
128
-    public Integer getSex() {
129
-        return sex;
130
-    }
131
-
132
-    public void setSex(Integer sex) {
133
-        this.sex = sex;
134
-    }
135
-
136
-    public Date getBirthday() {
137
-        return birthday;
138
-    }
139
-
140
-    public void setBirthday(Date birthday) {
141
-        this.birthday = birthday;
142
-    }
143
-
144
-    public String getPhone() {
145
-        return phone;
146
-    }
147
-
148
-    public void setPhone(String phone) {
149
-        this.phone = phone;
150
-    }
151
-
152
-    public String getMail() {
153
-        return mail;
154
-    }
155
-
156
-    public void setMail(String mail) {
157
-        this.mail = mail;
158
-    }
159
-
160
-    public String getAddress() {
161
-        return address;
162
-    }
163
-
164
-    public void setAddress(String address) {
165
-        this.address = address;
166
-    }
167
-
168
-    public String getExplain() {
169
-        return explain;
170
-    }
171
-
172
-    public void setExplain(String explain) {
173
-        this.explain = explain;
174
-    }
175
-
176
-    public Integer getUserSource() {
177
-        return userSource;
178
-    }
179
-
180
-    public void setUserSource(Integer userSource) {
181
-        this.userSource = userSource;
182
-    }
183
-
184
-    public Integer getStatus() {
185
-        return status;
186
-    }
187
-
188
-    public void setStatus(Integer status) {
189
-        this.status = status;
190
-    }
191
-
192
-    public String getCreateBy() {
193
-        return createBy;
194
-    }
195
-
196
-    public void setCreateBy(String createBy) {
197
-        this.createBy = createBy;
198
-    }
199
-
200
-    public Date getCreateTime() {
201
-        return createTime;
202
-    }
203
-
204
-    public void setCreateTime(Date createTime) {
205
-        this.createTime = createTime;
206
-    }
207
-
208
-    public String getUpdateBy() {
209
-        return updateBy;
210
-    }
211
-
212
-    public void setUpdateBy(String updateBy) {
213
-        this.updateBy = updateBy;
214
-    }
215
-
216
-    public Date getUpdateTime() {
217
-        return updateTime;
218
-    }
219
-
220
-    public void setUpdateTime(Date updateTime) {
221
-        this.updateTime = updateTime;
222
-    }
223
-
224
-    public String getRemark() {
225
-        return remark;
226
-    }
227
-
228
-    public void setRemark(String remark) {
229
-        this.remark = remark;
230
-    }
231
-
232
-    @Override
233
-    public String toString() {
234
-        return "UserModel{" +
235
-                ", id=" + id +
236
-                ", name=" + name +
237
-                ", nickname=" + nickname +
238
-                ", password=" + password +
239
-                ", photo=" + photo +
240
-                ", sex=" + sex +
241
-                ", birthday=" + birthday +
242
-                ", phone=" + phone +
243
-                ", mail=" + mail +
244
-                ", address=" + address +
245
-                ", explain=" + explain +
246
-                ", userSource=" + userSource +
247
-                ", status=" + status +
248
-                ", createBy=" + createBy +
249
-                ", createTime=" + createTime +
250
-                ", updateBy=" + updateBy +
251
-                ", updateTime=" + updateTime +
252
-                ", remark=" + remark +
253
-                "}";
254
-    }
255
-}

+ 11 - 11
src/main/java/com/unissoft/service/MyUserDetailService.java

@@ -1,8 +1,12 @@
1 1
 package com.unissoft.service;
2 2
 
3 3
 import com.alibaba.fastjson.JSONObject;
4
+import com.unissoft.dto.BaseDto;
5
+import com.unissoft.exception.MyRuntimeException;
4 6
 import com.unissoft.mapper.PublicMapper;
5
-import com.unissoft.model.UserModel;
7
+import com.unissoft.model.SysUser;
8
+import com.unissoft.result.ResultEnum;
9
+import com.unissoft.result.ResultView;
6 10
 import org.springframework.beans.factory.annotation.Autowired;
7 11
 import org.springframework.security.core.authority.SimpleGrantedAuthority;
8 12
 import org.springframework.security.core.userdetails.User;
@@ -11,10 +15,6 @@ import org.springframework.security.core.userdetails.UserDetailsService;
11 15
 import org.springframework.security.core.userdetails.UsernameNotFoundException;
12 16
 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
13 17
 import org.springframework.stereotype.Service;
14
-import com.unissoft.dto.BaseDto;
15
-import com.unissoft.exception.MyRuntimeException;
16
-import com.unissoft.result.ResultEnum;
17
-import com.unissoft.result.ResultView;
18 18
 
19 19
 import java.util.ArrayList;
20 20
 import java.util.List;
@@ -37,14 +37,14 @@ public class MyUserDetailService implements UserDetailsService {
37 37
     @Override
38 38
     public UserDetails loadUserByUsername(String name) throws UsernameNotFoundException {
39 39
         //查用户
40
-        UserModel userModel = publicMapper.getUserByName(name);
41
-        if (userModel == null) {
40
+        SysUser SysUser = publicMapper.getUserByName(name);
41
+        if (SysUser == null) {
42 42
             throw new MyRuntimeException(ResultView.error(ResultEnum.CODE_5));
43 43
         }
44 44
         System.err.println("当前登录的用户是:" + name);
45 45
 
46 46
         //查该用户拥有的角色
47
-        List<BaseDto> roleDtos = publicMapper.getRoleByUserId(userModel.getId());
47
+        List<BaseDto> roleDtos = publicMapper.getRoleByUserId(SysUser.getuId());
48 48
         List<SimpleGrantedAuthority> authorities = new ArrayList<>();
49 49
         if (roleDtos.size() == 0) {
50 50
             authorities.add(new SimpleGrantedAuthority("ROLE_NoRole"));
@@ -55,9 +55,9 @@ public class MyUserDetailService implements UserDetailsService {
55 55
             }
56 56
         }
57 57
 
58
-//        String password = {noop} + userModel.getPassword();
59
-        String jsonString = JSONObject.toJSONString(userModel);
60
-        String password = new BCryptPasswordEncoder().encode(userModel.getPassword());
58
+//        String password = {noop} + SysUser.getPassword();
59
+        String jsonString = JSONObject.toJSONString(SysUser);
60
+        String password = new BCryptPasswordEncoder().encode(SysUser.getuPassword());
61 61
         User user = new User(jsonString, password, authorities);
62 62
 //        User user = new User(name, password, authorities);
63 63
         return user;

+ 23 - 24
src/main/resources/mapper/PublicMapper.xml

@@ -3,26 +3,25 @@
3 3
 <mapper namespace="com.unissoft.mapper.PublicMapper">
4 4
 
5 5
     <!-- 通用查询映射结果 -->
6
-
7
-    <resultMap id="UserMap" type="com.unissoft.model.UserModel">
8
-        <id column="id" property="id"/>
9
-        <result column="name" property="name"/>
10
-        <result column="nickname" property="nickname"/>
11
-        <result column="password" property="password"/>
12
-        <result column="photo" property="photo"/>
13
-        <result column="sex" property="sex"/>
14
-        <result column="birthday" property="birthday"/>
15
-        <result column="phone" property="phone"/>
16
-        <result column="mail" property="mail"/>
17
-        <result column="address" property="address"/>
18
-        <result column="explain" property="explain"/>
19
-        <result column="user_source" property="userSource"/>
20
-        <result column="status" property="status"/>
21
-        <result column="create_by" property="createBy"/>
22
-        <result column="create_time" property="createTime"/>
23
-        <result column="update_by" property="updateBy"/>
24
-        <result column="update_time" property="updateTime"/>
25
-        <result column="remark" property="remark"/>
6
+    <resultMap id="UserMap" type="com.unissoft.model.SysUser">
7
+        <id column="u_id" property="uId" />
8
+        <result column="u_name" property="uName" />
9
+        <result column="u_nickname" property="uNickname" />
10
+        <result column="u_password" property="uPassword" />
11
+        <result column="u_photo" property="uPhoto" />
12
+        <result column="u_sex" property="uSex" />
13
+        <result column="u_birthday" property="uBirthday" />
14
+        <result column="u_phone" property="uPhone" />
15
+        <result column="u_mail" property="uMail" />
16
+        <result column="u_address" property="uAddress" />
17
+        <result column="u_explain" property="uExplain" />
18
+        <result column="u_user_source" property="uUserSource" />
19
+        <result column="u_status" property="uStatus" />
20
+        <result column="u_create_by" property="uCreateBy" />
21
+        <result column="u_create_time" property="uCreateTime" />
22
+        <result column="u_update_by" property="uUpdateBy" />
23
+        <result column="u_update_time" property="uUpdateTime" />
24
+        <result column="u_remark" property="uRemark" />
26 25
     </resultMap>
27 26
 
28 27
     <resultMap id="OauthClientDetailsMap" type="com.unissoft.model.OauthClientDetailsModel">
@@ -45,13 +44,13 @@
45 44
     </resultMap>
46 45
 
47 46
     <select id="getUserByName" resultMap="UserMap">
48
-        SELECT id,`name`,password FROM `user` WHERE `name` = #{name}
47
+        SELECT u_id,u_name,u_password FROM sys_user WHERE u_name = #{name}
49 48
     </select>
50 49
 
51 50
     <select id="getRoleByUserId" resultMap="BaseDtoMap">
52
-        SELECT t3.id,t3.name FROM `user` t1,user_role t2,role t3
53
-        WHERE  t1.`id` = t2.`user_id`
54
-        AND t2.`role_id` = t3.`id` AND t1.`id` = #{userId};
51
+       SELECT t3.r_id id,t3.r_name name FROM sys_user t1,sys_user_role t2,sys_role t3
52
+        WHERE  t1.u_id = t2.`user_id`
53
+        AND t2.`role_id` = t3.`r_id` AND t1.`u_id` = #{userId}
55 54
     </select>
56 55
 
57 56
     <select id="getOauthClientDetailsByClientId" resultMap="OauthClientDetailsMap">