Skip to content

Commit 3245a0a

Browse files
committed
kotlin
1 parent 91e9d09 commit 3245a0a

File tree

33 files changed

+1173
-1129
lines changed

33 files changed

+1173
-1129
lines changed

api/src/main/java/info/xiaomo/api/controller/AdminUserController.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import info.xiaomo.core.base.Result;
77
import info.xiaomo.core.constant.CodeConst;
88
import info.xiaomo.core.exception.UserNotFoundException;
9-
import info.xiaomo.core.untils.MD5Util;
9+
import info.xiaomo.core.untils.Md5Util;
1010
import info.xiaomo.core.untils.RandomUtil;
1111
import io.swagger.annotations.*;
1212
import org.springframework.beans.factory.annotation.Autowired;
@@ -70,7 +70,7 @@ public Result login(@PathVariable("userName") String userName, @PathVariable("pa
7070
if (adminModel == null) {
7171
return new Result(CodeConst.USER_NOT_FOUND.getResultCode(), CodeConst.USER_NOT_FOUND.getMessage());
7272
}
73-
if (!MD5Util.encode(password, adminModel.getSalt()).equals(adminModel.getPassword())) {
73+
if (!Md5Util.encode(password, adminModel.getSalt()).equals(adminModel.getPassword())) {
7474
return new Result(CodeConst.AUTH_FAILED.getResultCode(), CodeConst.AUTH_FAILED.getMessage());
7575
}
7676
return new Result<>(adminModel);
@@ -95,7 +95,7 @@ public Result add(@RequestBody AdminModel model) {
9595
}
9696
String salt = RandomUtil.createSalt();
9797
model.setSalt(salt);
98-
model.setPassword(MD5Util.encode(model.getPassword(), salt));
98+
model.setPassword(Md5Util.encode(model.getPassword(), salt));
9999
AdminModel saveModel = service.addAdminUser(model);
100100
return new Result<>(saveModel);
101101
}
@@ -254,7 +254,7 @@ public Result changePassword(@RequestBody AdminModel model) throws UserNotFoundE
254254
}
255255
String salt = RandomUtil.createSalt();
256256
adminModel.setSalt(salt);
257-
adminModel.setPassword(MD5Util.encode(model.getPassword(), salt));
257+
adminModel.setPassword(Md5Util.encode(model.getPassword(), salt));
258258
service.updateAdminUser(adminModel);
259259
return new Result<>(adminModel);
260260
}

api/src/main/java/info/xiaomo/api/controller/LinkController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,8 @@ public Result update(@RequestBody LinkModel model) {
243243
@ApiImplicitParam(name = "id", value = "唯一id", required = true, dataType = "Long", paramType = "path")
244244
})
245245
public Result delete(@PathVariable("id") Long id) {
246-
LinkModel LinkModel = service.findById(id);
247-
if (LinkModel == null) {
246+
LinkModel linkmodel = service.findById(id);
247+
if (linkmodel == null) {
248248
return new Result<>(CodeConst.NULL_DATA.getResultCode(), CodeConst.NULL_DATA.getMessage());
249249
}
250250
LinkModel delModel = service.delete(id);

api/src/main/java/info/xiaomo/api/controller/TechnologyController.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
import info.xiaomo.api.model.TechnologyModel;
44
import info.xiaomo.api.service.TechnologyService;
5-
import info.xiaomo.core.constant.CodeConst;
65
import info.xiaomo.core.base.BaseController;
76
import info.xiaomo.core.base.Result;
7+
import info.xiaomo.core.constant.CodeConst;
88
import io.swagger.annotations.Api;
99
import io.swagger.annotations.ApiImplicitParam;
1010
import io.swagger.annotations.ApiImplicitParams;
@@ -44,6 +44,7 @@ public TechnologyController(TechnologyService service) {
4444
}
4545

4646

47+
@Override
4748
@ApiOperation(value = "根据id查找技术", notes = "根据id查找技术",httpMethod = "GET", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
4849
@RequestMapping(value = "/findById/{id}",method = RequestMethod.GET)
4950
@ApiImplicitParams({
@@ -57,6 +58,7 @@ public Result findById(@PathVariable Long id) {
5758
return new Result<>(model);
5859
}
5960

61+
@Override
6062
@ApiOperation(value = "根据名字查找技术", notes = "根据名字查找技术",httpMethod = "GET", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
6163
@RequestMapping(value = "/findByName/{name}",method = RequestMethod.GET)
6264
@ApiImplicitParams({
@@ -125,6 +127,7 @@ public Result<Boolean> delByIds(@PathVariable List ids) {
125127
return null;
126128
}
127129

130+
@Override
128131
@ApiOperation(value = "查找所有", notes = "查找所有",httpMethod = "GET", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
129132
@RequestMapping(value = "/findAll",method = RequestMethod.GET)
130133
public Result findAll() {

api/src/main/java/info/xiaomo/api/controller/UserController.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
import info.xiaomo.api.model.UserModel;
44
import info.xiaomo.api.service.UserService;
5-
import info.xiaomo.core.constant.CodeConst;
6-
import info.xiaomo.core.constant.GenderConst;
75
import info.xiaomo.core.base.BaseController;
86
import info.xiaomo.core.base.Result;
7+
import info.xiaomo.core.constant.CodeConst;
8+
import info.xiaomo.core.constant.GenderConst;
99
import info.xiaomo.core.exception.UserNotFoundException;
10-
import info.xiaomo.core.untils.MD5Util;
1110
import info.xiaomo.core.untils.MailUtil;
11+
import info.xiaomo.core.untils.Md5Util;
1212
import info.xiaomo.core.untils.RandomUtil;
1313
import info.xiaomo.core.untils.TimeUtil;
1414
import io.swagger.annotations.Api;
@@ -80,8 +80,8 @@ public Result addUser(@RequestBody UserModel user) {
8080
return new Result(CodeConst.USER_REPEAT.getResultCode(), CodeConst.USER_REPEAT.getMessage());
8181
}
8282
String salt = RandomUtil.createSalt();
83-
user.setPassword(MD5Util.encode(user.getPassword(), salt));
84-
user.setValidateCode(MD5Util.encode(user.getEmail(), ""));
83+
user.setPassword(Md5Util.encode(user.getPassword(), salt));
84+
user.setValidateCode(Md5Util.encode(user.getEmail(), ""));
8585
user.setSalt(salt);
8686
service.addUser(user);
8787
return new Result<>(user);
@@ -128,7 +128,7 @@ public Result login(@PathVariable("email") String email, @PathVariable("password
128128
return new Result(CodeConst.USER_NOT_FOUND.getResultCode(), CodeConst.USER_NOT_FOUND.getMessage());
129129
}
130130
//密码不正确
131-
if (!MD5Util.encode(password, userModel.getSalt()).equals(userModel.getPassword())) {
131+
if (!Md5Util.encode(password, userModel.getSalt()).equals(userModel.getPassword())) {
132132
return new Result(CodeConst.AUTH_FAILED.getResultCode(), CodeConst.AUTH_FAILED.getMessage());
133133
}
134134
return new Result<>(userModel);
@@ -149,7 +149,7 @@ public Result changePassword(@RequestBody UserModel user) throws UserNotFoundExc
149149
return new Result(CodeConst.USER_NOT_FOUND.getResultCode(), CodeConst.USER_NOT_FOUND.getMessage());
150150
}
151151
String salt = RandomUtil.createSalt();
152-
userByEmail.setPassword(MD5Util.encode(user.getPassword(), salt));
152+
userByEmail.setPassword(Md5Util.encode(user.getPassword(), salt));
153153
userByEmail.setNickName(user.getNickName());
154154
userByEmail.setSalt(salt);
155155
UserModel updateUser = service.updateUser(userByEmail);
@@ -175,7 +175,7 @@ public Result update(@RequestBody UserModel user) throws UserNotFoundException {
175175
userModel.setPhone(user.getPhone());
176176
userModel.setAddress(user.getAddress());
177177
userModel.setGender(user.getGender());
178-
userModel.setValidateCode(MD5Util.encode(user.getEmail(), ""));
178+
userModel.setValidateCode(Md5Util.encode(user.getEmail(), ""));
179179
UserModel updateUser = service.updateUser(userModel);
180180
return new Result<>(updateUser);
181181
}
@@ -228,7 +228,7 @@ public Result validateEmail(@RequestBody UserModel user
228228
return new Result(CodeConst.USER_REPEAT.getResultCode(), CodeConst.USER_REPEAT.getMessage());
229229
}
230230
//验证码是否过期
231-
if (user.getRegisterTime() + TimeUtil.ONE_DAY_IN_MILLISECONDS * 2 < TimeUtil.getNowOfMills()) {
231+
if (user.getRegisterTime() + TimeUtil.ONE_DAY_IN_MILLISECONDS < TimeUtil.getNowOfMills()) {
232232
LOGGER.info("用户{}使用己过期的激活码{}激活邮箱失败!", user.getEmail(), user.getEmail());
233233
return new Result(CodeConst.TIME_PASSED.getResultCode(), CodeConst.TIME_PASSED.getMessage());
234234
}
@@ -237,12 +237,12 @@ public Result validateEmail(@RequestBody UserModel user
237237
userModel = new UserModel();
238238
userModel.setNickName(user.getNickName());
239239
userModel.setEmail(user.getEmail());
240-
userModel.setGender(GenderConst.secret);
241-
userModel.setValidateCode(MD5Util.encode(user.getEmail(), salt));
240+
userModel.setGender(GenderConst.SECRET);
241+
userModel.setValidateCode(Md5Util.encode(user.getEmail(), salt));
242242
userModel.setPhone(0L);
243243
userModel.setSalt(salt);
244244
userModel.setAddress("");
245-
userModel.setPassword(MD5Util.encode(user.getPassword(), salt));
245+
userModel.setPassword(Md5Util.encode(user.getPassword(), salt));
246246
userModel = service.addUser(userModel);
247247
LOGGER.info("用户{}使用激活码{}激活邮箱成功!", userModel.getEmail(), userModel.getValidateCode());
248248
return new Result<>(userModel);

api/src/main/java/info/xiaomo/api/model/UserModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,5 @@ public class UserModel extends BaseModel implements Serializable {
7777

7878
@ApiModelProperty(value = "注册时间(时间戳)")
7979
@Column(name = "RegisterTime")
80-
private Long RegisterTime = 0L;
80+
private Long registerTime = 0L;
8181
}

core/src/main/java/info/xiaomo/core/constant/CodeConst.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@
99
* @author : xiaomo
1010
* github: https://github.com/xiaomoinfo
1111
* email: xiaomo@xiaomo.info
12-
12+
* <p>
1313
* Date: 2016/10/29 10:59
1414
* Description: 错误码
1515
* Copyright(©) 2015 by xiaomo.
1616
*/
1717
public enum CodeConst {
18+
/**
19+
* success
20+
*/
1821
SUCCESS(200, "成功"),
1922
NOT_FOUNT(404, "找不到"),
2023
REPEAT(992, "数据重复"),

core/src/main/java/info/xiaomo/core/constant/GenderConst.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
**/
1717
public interface GenderConst {
1818

19-
int secret = 0;
19+
int SECRET = 0;
2020

21-
int man = 1;
21+
int MAN = 1;
2222

23-
int woman = 2;
23+
int WOMAN = 2;
2424

2525
}

core/src/main/java/info/xiaomo/core/untils/CastUtil.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
**/
2222

2323
public class CastUtil {
24-
protected static final ByteArrayOutputStream out = new ByteArrayOutputStream();
24+
protected static final ByteArrayOutputStream OUT = new ByteArrayOutputStream();
2525
protected static ObjectOutputStream oos;
2626

2727
public CastUtil() {
@@ -208,20 +208,20 @@ public static Object bytesToObject(byte[] bytes) {
208208
}
209209

210210
public static byte[] objectToBytes(Object obj) throws IOException {
211-
out.reset();
211+
OUT.reset();
212212

213213
byte[] var2;
214214
try {
215215
if (oos == null) {
216-
oos = new ObjectOutputStream(out);
216+
oos = new ObjectOutputStream(OUT);
217217
} else {
218218
oos.reset();
219219
}
220220

221221
oos.writeObject(obj);
222-
var2 = out.toByteArray();
222+
var2 = OUT.toByteArray();
223223
} finally {
224-
out.close();
224+
OUT.close();
225225
}
226226

227227
return var2;

core/src/main/java/info/xiaomo/core/untils/CharUtil.java

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
/**
77
* <p>Title:字符编码工具类 </p>
88
*
9-
* @version 1.0
109
* @author : xiaomo
10+
* @version 1.0
1111
*/
1212
public class CharUtil {
1313

1414
/**
1515
* 转换编码 ISO-8859-1到GB2312
1616
*/
17-
public static String ISO2GB(String text) {
17+
public static String iso2gb(String text) {
1818
String result;
1919
try {
2020
result = new String(text.getBytes("ISO-8859-1"), "GB2312");
@@ -27,7 +27,7 @@ public static String ISO2GB(String text) {
2727
/**
2828
* 转换编码 GB2312到ISO-8859-1
2929
*/
30-
public static String GB2ISO(String text) {
30+
public static String gb2iso(String text) {
3131
String result = "";
3232
try {
3333
result = new String(text.getBytes("GB2312"), "ISO-8859-1");
@@ -40,7 +40,7 @@ public static String GB2ISO(String text) {
4040
/**
4141
* Utf8URL编码
4242
*/
43-
public static String Utf8URLEncode(String text) {
43+
public static String utf8urlencode(String text) {
4444
StringBuilder result = new StringBuilder();
4545
for (int i = 0; i < text.length(); i++) {
4646

@@ -71,7 +71,7 @@ public static String Utf8URLEncode(String text) {
7171
/**
7272
* Utf8URL解码
7373
*/
74-
public static String Utf8URLDecode(String text) {
74+
public static String utf8urldecode(String text) {
7575
String result = "";
7676
int p;
7777
if (text != null && text.length() > 0) {
@@ -86,7 +86,7 @@ public static String Utf8URLDecode(String text) {
8686
if (Objects.equals(text, "") || text.length() < 9) {
8787
return result;
8888
}
89-
result += CodeToWord(text.substring(0, 9));
89+
result += codetoword(text.substring(0, 9));
9090
text = text.substring(9, text.length());
9191
p = text.indexOf("%e");
9292
}
@@ -97,9 +97,9 @@ public static String Utf8URLDecode(String text) {
9797
/**
9898
* utf8URL编码转字符
9999
*/
100-
private static String CodeToWord(String text) {
100+
private static String codetoword(String text) {
101101
String result;
102-
if (Utf8codeCheck(text)) {
102+
if (utf8codecheck(text)) {
103103
byte[] code = new byte[3];
104104
code[0] = (byte) (Integer.parseInt(text.substring(1, 3), 16) - 256);
105105
code[1] = (byte) (Integer.parseInt(text.substring(4, 6), 16) - 256);
@@ -118,9 +118,10 @@ private static String CodeToWord(String text) {
118118
/**
119119
* 编码是否有效
120120
*/
121-
private static boolean Utf8codeCheck(String text) {
121+
private static boolean utf8codecheck(String text) {
122122
String sign = "";
123-
if (text.startsWith("%e")) {
123+
String prefix = "%e";
124+
if (text.startsWith(prefix)) {
124125
for (int p = 0; p != -1; ) {
125126
p = text.indexOf("%", p);
126127
if (p != -1) {
@@ -138,10 +139,11 @@ private static boolean Utf8codeCheck(String text) {
138139
public static boolean isUtf8Url(String text) {
139140
text = text.toLowerCase();
140141
int p = text.indexOf("%");
141-
if (p != -1 && text.length() - p > 9) {
142-
text = text.substring(p, p + 9);
142+
int nine = 9;
143+
if (p != -1 && text.length() - p > nine) {
144+
text = text.substring(p, p + nine);
143145
}
144-
return Utf8codeCheck(text);
146+
return utf8codecheck(text);
145147
}
146148

147149
/**
@@ -162,16 +164,16 @@ public static char regularize(char input) {
162164

163165
public static void main(String[] args) {
164166
String url;
165-
System.out.println(Utf8URLEncode("小莫"));
166-
System.out.println(ISO2GB("小莫"));
167-
System.out.println(GB2ISO("小莫"));
167+
System.out.println(utf8urlencode("小莫"));
168+
System.out.println(iso2gb("小莫"));
169+
System.out.println(gb2iso("小莫"));
168170
url = "http://www.google.com/search?hl=zh-CN&newwindow=1&q=%E4%B8%AD%E5%9B%BD%E5%A4%A7%E7%99%BE%E7%A7%91%E5%9C%A8%E7%BA%BF%E5%85%A8%E6%96%87%E6%A3%80%E7%B4%A2&btnG=%E6%90%9C%E7%B4%A2&lr=";
169171
if (CharUtil.isUtf8Url(url)) {
170-
System.out.println(CharUtil.Utf8URLDecode(url));
172+
System.out.println(CharUtil.utf8urldecode(url));
171173
}
172174
url = "http://www.baidu.com/baidu?word=%D6%D0%B9%FA%B4%F3%B0%D9%BF%C6%D4%DA%CF%DF%C8%AB%CE%C4%BC%EC%CB%F7&tn=myie2dg";
173175
if (CharUtil.isUtf8Url(url)) {
174-
System.out.println(CharUtil.Utf8URLDecode(url));
176+
System.out.println(CharUtil.utf8urldecode(url));
175177
}
176178
}
177179

0 commit comments

Comments
 (0)