Skip to content

Commit 1828da8

Browse files
对异常信息的修改,并统一App请求状态码
1 parent 8e5033b commit 1828da8

File tree

20 files changed

+242
-146
lines changed

20 files changed

+242
-146
lines changed

.idea/workspace.xml

Lines changed: 143 additions & 136 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/com/yjz/notepad/bean/User.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
public class User {
1515

1616
private Long id;
17-
private String username;
1817
private String phone;
18+
private String password;
1919
private Date register_time;
2020

2121
}

src/main/java/com/yjz/notepad/controller/UserController.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.yjz.notepad.bean.R;
44
import com.yjz.notepad.bean.User;
5+
import com.yjz.notepad.exception.BaseException;
56
import com.yjz.notepad.service.IUserService;
67
import com.yjz.notepad.util.StringUtil;
78
import org.springframework.stereotype.Controller;
@@ -33,8 +34,14 @@ public HashMap<String, Object> add(User user) {
3334

3435
System.out.println(user.toString());
3536

36-
if (StringUtil.isEmpty(user.getUsername()) || StringUtil.isEmpty(user.getPhone())) {
37-
return R.error(400, "用户数据为空");
37+
for (User user1 : userService.queryUserAll()) {
38+
if (user1.getPhone().equals(user.getPhone())) {
39+
return R.error(BaseException.ERROR_HTTP_300, "用戶已存在");
40+
}
41+
}
42+
43+
if (StringUtil.isEmpty(user.getPassword()) || StringUtil.isEmpty(user.getPhone())) {
44+
return R.ok("用户数据为空");
3845
}
3946

4047
if (user.getRegister_time() == null) {
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package com.yjz.notepad.exception;
2+
3+
/**
4+
* author: YJZ
5+
* time : 2017/3/12 13:00
6+
* desc : 异常的基类
7+
*/
8+
public class BaseException extends Exception {
9+
10+
/*API错误*/
11+
public static final int API_ERROR = 0x0;
12+
/*网络错误*/
13+
public static final int NETWORD_ERROR = 0x1;
14+
/*http_错误*/
15+
public static final int HTTP_ERROR = 0x2;
16+
/*json错误*/
17+
public static final int JSON_ERROR = 0x3;
18+
/*未知错误*/
19+
public static final int UNKNOWN_ERROR = 0x4;
20+
/*运行时异常-包含自定义异常*/
21+
public static final int RUNTIME_ERROR = 0x5;
22+
/*无法解析该域名*/
23+
public static final int UNKOWNHOST_ERROR = 0x6;
24+
/*连接网络超时*/
25+
public static final int SOCKET_TIMEOUT_ERROR = 0x7;
26+
/*无网络连接*/
27+
public static final int SOCKET_ERROR = 0x8;
28+
29+
// api /////////////////////////////////////////
30+
// 服务器错误
31+
public static final int ERROR_API_SYSTEM = 10000;
32+
// 登录错误,用户名密码错误
33+
public static final int ERROR_API_LOGIN = 10001;
34+
//调用无权限的API
35+
public static final int ERROR_API_NO_PERMISSION = 10002;
36+
//账户被冻结
37+
public static final int ERROR_API_ACCOUNT_FREEZE = 10003;
38+
39+
/**
40+
* ------token失效------
41+
**/
42+
public static final int ERROR_API_LOGIN_TOKEN = 10004;
43+
// http
44+
public static final int ERROR_HTTP_300 = 300;
45+
46+
public static final int ERROR_HTTP_400 = 400;
47+
48+
public static final int ERROR_HTTP_404 = 404;
49+
50+
public static final int ERROR_HTTP_405 = 405;
51+
52+
public static final int ERROR_HTTP_500 = 500;
53+
54+
55+
private int code;
56+
private String displayMsg;
57+
58+
public BaseException() {
59+
}
60+
61+
public BaseException(int code, String displayMsg) {
62+
this.code = code;
63+
this.displayMsg = displayMsg;
64+
}
65+
66+
public int getCode() {
67+
return code;
68+
}
69+
70+
public void setCode(int code) {
71+
this.code = code;
72+
}
73+
74+
public String getDisplayMsg() {
75+
return displayMsg;
76+
}
77+
78+
public void setDisplayMsg(String displayMsg) {
79+
this.displayMsg = displayMsg;
80+
}
81+
82+
}

src/main/java/com/yjz/notepad/test/UserTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void testQueryUserAll() {
3535
@Test
3636
public void testAddUserByObject() {
3737
User user = new User();
38-
user.setUsername("YJZ");
38+
user.setPassword("YJZ");
3939
user.setPhone("17621859608");
4040
Date date = new Date();
4141
user.setRegister_time(date);

src/main/resource/mapper/UserDao.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<selectKey resultType="Long" order="AFTER" keyProperty="id">
1414
SELECT LAST_INSERT_ID()
1515
</selectKey>
16-
INSERT INTO user(username,phone,register_time) VALUES(#{username},#{phone},#{register_time});
16+
INSERT INTO user(phone,password,register_time) VALUES(#{phone},#{password},#{register_time});
1717
</insert>
1818

1919
<delete id="deleteUserById" parameterType="Long">

src/main/resource/sql/user.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
DROP TABLE IF EXISTS `user`;
55
CREATE TABLE `user` (
66
`id` int(11) NOT NULL AUTO_INCREMENT,
7-
`username` varchar(32) NOT NULL COMMENT '用户名称',
87
`phone` varchar(32) NOT NULL COMMENT '电话号码',
8+
`password` varchar(32) NOT NULL COMMENT '密码',
99
`register_time` datetime NOT NULL COMMENT '注册时间',
1010
PRIMARY KEY (`id`)
1111
) ENGINE=InnoDB AUTO_INCREMENT=27 DEFAULT CHARSET=utf8;
0 Bytes
Binary file not shown.
374 Bytes
Binary file not shown.
1.64 KB
Binary file not shown.

0 commit comments

Comments
 (0)