Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
ioc_sixiang_license
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zengtianlai3
ioc_sixiang_license
Commits
989a357e
Commit
989a357e
authored
Jun 09, 2022
by
zengtianlai3
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加全局异常处理
parent
c674d9bf
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
75 additions
and
5 deletions
+75
-5
GlobalExceptionHandler.java
...a/iot/sixiang/license/handler/GlobalExceptionHandler.java
+29
-0
IotLicenseException.java
...java/iot/sixiang/license/handler/IotLicenseException.java
+18
-0
UserMapper.java
.../src/main/java/iot/sixiang/license/mapper/UserMapper.java
+2
-0
BaseResult.java
...e/src/main/java/iot/sixiang/license/model/BaseResult.java
+6
-0
PageResult.java
...e/src/main/java/iot/sixiang/license/model/PageResult.java
+3
-3
ResResult.java
...se/src/main/java/iot/sixiang/license/model/ResResult.java
+5
-0
UserVo.java
...se/src/main/java/iot/sixiang/license/model/vo/UserVo.java
+1
-1
UserServiceImpl.java
...ava/iot/sixiang/license/service/impl/UserServiceImpl.java
+5
-0
UserMapper.xml
license/src/main/resources/mapper/UserMapper.xml
+6
-1
No files found.
license/src/main/java/iot/sixiang/license/handler/GlobalExceptionHandler.java
0 → 100644
View file @
989a357e
package
iot
.
sixiang
.
license
.
handler
;
import
iot.sixiang.license.model.BaseResult
;
import
org.springframework.web.bind.annotation.ControllerAdvice
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.bind.annotation.ResponseBody
;
/**
* Created by m33 on 2022/6/9 11:01
*/
@ControllerAdvice
public
class
GlobalExceptionHandler
{
//指定出现什么异常执行这个方法
@ExceptionHandler
(
Exception
.
class
)
@ResponseBody
//为了返回数据
public
BaseResult
error
(
Exception
e
){
e
.
printStackTrace
();
return
BaseResult
.
fail
().
msg
(
"执行了全局的异常类..."
);
}
//自定义异常
@ExceptionHandler
(
IotLicenseException
.
class
)
@ResponseBody
//为了返回数据
public
BaseResult
error
(
IotLicenseException
e
){
e
.
printStackTrace
();
return
BaseResult
.
fail
().
msg
(
e
.
getMsg
()).
code
(
e
.
getCode
());
}
}
license/src/main/java/iot/sixiang/license/handler/IotLicenseException.java
0 → 100644
View file @
989a357e
package
iot
.
sixiang
.
license
.
handler
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
/**
* Created by m33 on 2022/6/9 11:13
*/
@Data
@AllArgsConstructor
//生成有参构造
@NoArgsConstructor
//生成无参构造
public
class
IotLicenseException
extends
RuntimeException
{
private
Integer
code
;
private
String
msg
;
//异常信息
}
license/src/main/java/iot/sixiang/license/mapper/UserMapper.java
View file @
989a357e
...
...
@@ -24,4 +24,6 @@ public interface UserMapper extends BaseMapper<User> {
boolean
updateUser
(
int
userId
,
String
password
);
List
<
UserVo
>
getUserList
(
String
userName
,
String
company
);
User
getUserByUserName
(
String
userName
);
}
license/src/main/java/iot/sixiang/license/model/BaseResult.java
View file @
989a357e
...
...
@@ -30,6 +30,12 @@ public class BaseResult {
return
respResult
;
}
public
BaseResult
code
(
int
code
)
{
this
.
code
=
code
;
return
this
;
}
public
BaseResult
msg
(
String
message
)
{
this
.
msg
=
message
;
return
this
;
...
...
license/src/main/java/iot/sixiang/license/model/PageResult.java
View file @
989a357e
...
...
@@ -8,17 +8,17 @@ public class PageResult {
private
int
code
;
private
String
msg
;
private
int
page
_n
o
;
private
int
page
N
o
;
private
int
pages
;
private
int
total
;
private
Object
record
;
public
PageResult
(
int
code
,
String
msg
,
int
page
_n
o
,
int
pages
,
int
total
,
Object
record
)
{
public
PageResult
(
int
code
,
String
msg
,
int
page
N
o
,
int
pages
,
int
total
,
Object
record
)
{
super
();
this
.
code
=
code
;
this
.
msg
=
msg
;
this
.
page
_no
=
page_n
o
;
this
.
page
No
=
pageN
o
;
this
.
pages
=
pages
;
this
.
total
=
total
;
this
.
record
=
record
;
...
...
license/src/main/java/iot/sixiang/license/model/ResResult.java
View file @
989a357e
...
...
@@ -30,6 +30,11 @@ public class ResResult {
return
respResult
;
}
public
ResResult
code
(
int
code
)
{
this
.
code
=
code
;
return
this
;
}
public
ResResult
msg
(
String
message
)
{
this
.
msg
=
message
;
return
this
;
...
...
license/src/main/java/iot/sixiang/license/model/vo/UserVo.java
View file @
989a357e
...
...
@@ -8,5 +8,5 @@ import lombok.Data;
*/
@Data
public
class
UserVo
extends
User
{
public
int
c
ount
;
public
int
deviceC
ount
;
}
license/src/main/java/iot/sixiang/license/service/impl/UserServiceImpl.java
View file @
989a357e
...
...
@@ -3,6 +3,7 @@ package iot.sixiang.license.service.impl;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
iot.sixiang.license.entity.User
;
import
iot.sixiang.license.handler.IotLicenseException
;
import
iot.sixiang.license.mapper.UserMapper
;
import
iot.sixiang.license.model.PageInfoModel
;
import
iot.sixiang.license.model.vo.UserVo
;
...
...
@@ -58,6 +59,10 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
if
(
JsonUtil
.
isNull
(
userName
)
||
JsonUtil
.
isNull
(
company
))
{
return
false
;
}
User
res
=
userMapper
.
getUserByUserName
(
userName
);
if
(
res
!=
null
)
{
throw
new
IotLicenseException
(
400
,
"用户名已存在"
);
}
return
userMapper
.
addUser
(
userName
,
company
,
password
);
}
...
...
license/src/main/resources/mapper/UserMapper.xml
View file @
989a357e
...
...
@@ -15,7 +15,7 @@
</update>
<select
id=
"getUserList"
resultType=
"iot.sixiang.license.model.vo.UserVo"
>
SELECT user.user_id, user_name, password, company, COUNT(sn) AS
c
ount
SELECT user.user_id, user_name, password, company, COUNT(sn) AS
deviceC
ount
FROM USER LEFT JOIN device ON user.user_id = device.user_id
where 1=1
<if
test=
"null != userName and '' != userName"
>
...
...
@@ -26,4 +26,9 @@
</if>
GROUP BY user.user_id
</select>
<select
id=
"getUserByUserName"
resultType=
"iot.sixiang.license.entity.User"
>
select user_id from user where user_name = #{userName}
</select>
</mapper>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment