Skip to content

Commit da4ba58

Browse files
committed
1. 修改模版包路径
1 parent fa21c6a commit da4ba58

File tree

13 files changed

+228
-48
lines changed

13 files changed

+228
-48
lines changed

otow-frame/springbootframe/super/src/main/java/com/example/config/BaseContext.java renamed to otow-frame/springbootframe/super/src/main/java/com/example/common/BaseContext.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
package com.example.framepack.config;
2-
1+
package com.example.common;
32
// 线程方法
43
public class BaseContext {
4+
55
// 定义一个静态的 ThreadLocal 变量,用于存储线程相关的用户上下文数据
66
private static final ThreadLocal<UserContext> userContextThreadLocal = new ThreadLocal<>();
77

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.example.common;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Data;
5+
6+
@AllArgsConstructor
7+
@Data
8+
public class R<T> {
9+
10+
private String code;
11+
12+
private String message;
13+
14+
private T data;
15+
16+
public static <T> R<T> success(String message, T data) {
17+
return new R<T>(RCode.SUCCESS.getCode(), message, data);
18+
}
19+
20+
public static <T> R<T> success(String message) {
21+
return success(message, null);
22+
}
23+
24+
public static <T> R<T> success() {
25+
return success(RCode.SUCCESS.getMessage());
26+
}
27+
28+
public static <T> R<T> success(T data) {
29+
return success(RCode.SUCCESS.getMessage(), data);
30+
}
31+
32+
public static <T> R<T> error(String code, String message) {
33+
return new R<>(code, message, null);
34+
}
35+
36+
public static <T> R<T> error(String message) {
37+
return error(RCode.ERROR.getCode(), message);
38+
}
39+
40+
public static <T> R<T> error() {
41+
return error(RCode.ERROR.getMessage());
42+
}
43+
44+
public static <T> R<T> error(RCode rCode) {
45+
return error(rCode.getCode(), rCode.getMessage());
46+
}
47+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.example.common;
2+
3+
import lombok.Getter;
4+
5+
@Getter
6+
public enum RCode {
7+
8+
// 成功响应
9+
SUCCESS("200", "成功"),
10+
11+
/**
12+
* 失败返回码
13+
*/
14+
ERROR("400", "服务器繁忙,请稍后重试"),
15+
16+
NUMBER_OUT("402", "数量上限超出"),
17+
18+
/**
19+
* 参数异常
20+
*/
21+
PARAMS_ERROR("20001", "参数异常或者格式错误");
22+
23+
/**
24+
* 自定义状态码
25+
**/
26+
private final String code;
27+
28+
/**
29+
* 自定义描述
30+
**/
31+
private final String message;
32+
33+
RCode(String code, String message) {
34+
this.code = code;
35+
this.message = message;
36+
}
37+
}
38+

otow-frame/springbootframe/super/src/main/java/com/example/common/Result.java

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.example.common.exception;
2+
3+
import lombok.Data;
4+
import lombok.EqualsAndHashCode;
5+
6+
@EqualsAndHashCode(callSuper = true)
7+
@Data
8+
public class ServeException extends RuntimeException {
9+
10+
/**
11+
* 状态码
12+
*/
13+
private String code = RCode.ERROR.getCode();
14+
15+
/**
16+
* 异常消息
17+
*/
18+
private String message = RCode.ERROR.getMessage();
19+
20+
21+
public ServeException(String code, String message) {
22+
this.code = code;
23+
this.message = message;
24+
}
25+
26+
public ServeException(String message) {
27+
this.message = message;
28+
}
29+
30+
public ServeException(RCode rCode) {
31+
this.code = rCode.getCode();
32+
this.message = rCode.getMessage();
33+
}
34+
35+
public ServeException(RCode rCode, String addMessage) {
36+
this.code = rCode.getCode();
37+
this.message = rCode.getMessage() + addMessage;
38+
}
39+
40+
public static ServeException of(RCode rCode) {
41+
return new ServeException(rCode.getCode(), rCode.getMessage());
42+
}
43+
44+
public static ServeException of(RCode rCode, String addMessage) {
45+
return new ServeException(rCode.getCode(), rCode.getMessage() + addMessage);
46+
}
47+
48+
public static ServeException of(String code, String msg) {
49+
return new ServeException(code, msg);
50+
}
51+
52+
public static ServeException of(String msg) {
53+
return new ServeException(RCode.ERROR.getCode(), msg);
54+
}
55+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.example.config;
2+
3+
import cn.hutool.core.lang.Snowflake;
4+
import cn.hutool.core.util.IdUtil;
5+
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
6+
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
7+
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
8+
import org.apache.ibatis.reflection.MetaObject;
9+
import org.springframework.context.annotation.Bean;
10+
import org.springframework.stereotype.Component;
11+
12+
import java.util.Date;
13+
14+
@Component
15+
public class MyBatisConfig implements MetaObjectHandler {
16+
17+
Snowflake secondSnow = IdUtil.getSnowflake(1, 1);
18+
19+
@Bean
20+
public MybatisPlusInterceptor paginationInterceptor(){
21+
//新建MybatisPlus拦截器
22+
MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
23+
//新建分页拦截器paginationInnerInterceptor
24+
PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();
25+
//设置分页拦截器的一些属性
26+
paginationInnerInterceptor.setOverflow(true);
27+
paginationInnerInterceptor.setMaxLimit(100L);
28+
//把分页拦截器添加到MybatisPlus拦截器中
29+
mybatisPlusInterceptor.addInnerInterceptor(paginationInnerInterceptor);
30+
//添加组件,大功告成!
31+
return mybatisPlusInterceptor;
32+
}
33+
34+
@Override
35+
public void insertFill(MetaObject metaObject) {
36+
this.strictInsertFill(metaObject, "id", String.class, secondSnow.nextIdStr());
37+
this.strictInsertFill(metaObject, "createTime", Date.class, new Date());
38+
}
39+
40+
41+
42+
@Override
43+
public void updateFill(MetaObject metaObject) {
44+
this.strictUpdateFill(metaObject, "updateTime", Date.class, new Date());
45+
}
46+
}

otow-frame/springbootframe/super/src/main/java/com/example/utils/DateTimeUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.example.framepack.utils;
1+
package com.example.utils;
22

33
import java.time.*;
44
import java.time.format.DateTimeFormatter;

otow-frame/springbootframe/super/src/main/java/com/example/utils/RandomUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.example.framepack.utils;
1+
package com.example.utils;
22

33
import java.util.Random;
44

otow-frame/springbootframe/super/src/main/java/com/example/utils/StringUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.example.framepack.utils;
1+
package com.example.utils;
22

33
import java.util.Arrays;
44
import java.util.List;

src/main/java/com/tml/otowbackend/core/config/MyBatisConfig.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
package com.tml.otowbackend.core.config;
22

3+
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
34
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
45
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
56
import org.apache.ibatis.reflection.MetaObject;
67
import org.springframework.context.annotation.Bean;
7-
import org.springframework.context.annotation.Configuration;
88
import org.springframework.stereotype.Component;
99

1010
import java.util.Date;
1111

12-
/**
13-
* @Description
14-
* @Author welsir
15-
* @Date 2024/11/20 11:14
16-
*/
1712
@Component
18-
public class MyBatisConfig implements com.baomidou.mybatisplus.core.handlers.MetaObjectHandler{
13+
public class MyBatisConfig implements MetaObjectHandler {
1914

2015
@Bean
2116
public MybatisPlusInterceptor paginationInterceptor(){
@@ -39,6 +34,8 @@ public void insertFill(MetaObject metaObject) {
3934
this.strictInsertFill(metaObject, "createTime", Date.class, new Date());
4035
}
4136

37+
38+
4239
@Override
4340
public void updateFill(MetaObject metaObject) {
4441
this.strictUpdateFill(metaObject, "updateTime", Date.class, new Date());

0 commit comments

Comments
 (0)