Skip to content

Commit f697329

Browse files
committed
init
1 parent 0dc6c86 commit f697329

File tree

9 files changed

+191
-21
lines changed

9 files changed

+191
-21
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.quick.controller;
2+
3+
4+
import org.springframework.web.bind.annotation.RequestMapping;
5+
6+
import org.springframework.web.bind.annotation.RestController;
7+
8+
/**
9+
* <p>
10+
* 前端控制器
11+
* </p>
12+
*
13+
* @author vector4wang
14+
* @since 2023-10-17
15+
*/
16+
@RestController
17+
@RequestMapping("/depot-entity")
18+
public class DepotController {
19+
20+
}
21+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.quick.entity;
2+
3+
import com.baomidou.mybatisplus.annotation.IdType;
4+
import com.baomidou.mybatisplus.annotation.TableField;
5+
import com.baomidou.mybatisplus.annotation.TableId;
6+
import com.baomidou.mybatisplus.annotation.TableName;
7+
import java.io.Serializable;
8+
import lombok.Getter;
9+
import lombok.Setter;
10+
11+
/**
12+
* <p>
13+
*
14+
* </p>
15+
*
16+
* @author vector4wang
17+
* @since 2023-10-17
18+
*/
19+
@Getter
20+
@Setter
21+
@TableName("depot")
22+
public class DepotEntity implements Serializable {
23+
24+
private static final long serialVersionUID = 1L;
25+
26+
@TableId(value = "id", type = IdType.AUTO)
27+
private Integer id;
28+
29+
@TableField("pid")
30+
private Integer pid;
31+
32+
@TableField("code")
33+
private String code;
34+
35+
36+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.quick.mapper;
2+
3+
import com.quick.entity.DepotEntity;
4+
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5+
6+
/**
7+
* <p>
8+
* Mapper 接口
9+
* </p>
10+
*
11+
* @author vector4wang
12+
* @since 2023-10-17
13+
*/
14+
public interface DepotMapper extends BaseMapper<DepotEntity> {
15+
16+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3+
<mapper namespace="com.quick.mapper.DepotMapper">
4+
5+
<!-- 通用查询映射结果 -->
6+
<resultMap id="BaseResultMap" type="com.quick.entity.DepotEntity">
7+
<id column="id" property="id" />
8+
<result column="pid" property="pid" />
9+
<result column="code" property="code" />
10+
</resultMap>
11+
12+
<!-- 通用查询结果列 -->
13+
<sql id="Base_Column_List">
14+
id, pid, code
15+
</sql>
16+
17+
</mapper>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.quick.service;
2+
3+
import com.quick.entity.DepotEntity;
4+
import com.baomidou.mybatisplus.extension.service.IService;
5+
6+
/**
7+
* <p>
8+
* 服务类
9+
* </p>
10+
*
11+
* @author vector4wang
12+
* @since 2023-10-17
13+
*/
14+
public interface DepotService extends IService<DepotEntity> {
15+
16+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.quick.service.impl;
2+
3+
import com.quick.entity.DepotEntity;
4+
import com.quick.mapper.DepotMapper;
5+
import com.quick.service.DepotService;
6+
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
7+
import org.springframework.stereotype.Service;
8+
9+
/**
10+
* <p>
11+
* 服务实现类
12+
* </p>
13+
*
14+
* @author vector4wang
15+
* @since 2023-10-17
16+
*/
17+
@Service
18+
public class DepotServiceImp extends ServiceImpl<DepotMapper, DepotEntity> implements DepotService {
19+
20+
}
Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
package com.quick.common.base.controller;
1+
package com.quick.common.base.rest;
22

33
/**
44
* 后续可在此提供公共方法
55
*/
66
public interface BaseController {
77

8-
default String toJSON(ArgusResponse responseBody) {
9-
String result = JsonUtil.serialize(responseBody);
10-
return result;
8+
default <T> BaseResp<T> success(T data, String msg) {
9+
return BaseResp.success(data, msg);
1110
}
1211

12+
default <T> BaseResp<String> fail(String msg) {
13+
return BaseResp.fail(msg);
14+
}
15+
16+
default <T> BaseResp<String> fail(ResultStatus code, String msg) {
17+
return BaseResp.fail(code, msg);
18+
}
1319

1420
}

quick-platform-common/src/main/java/com/quick/common/base/rest/BaseResp.java

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class BaseResp<T> {
99
/**
1010
* 返回码
1111
*/
12-
private int code;
12+
private ResultStatus code;
1313

1414
/**
1515
* 返回信息描述
@@ -23,11 +23,12 @@ public class BaseResp<T> {
2323

2424
private long currentTime;
2525

26-
public int getCode() {
26+
27+
public ResultStatus getCode() {
2728
return code;
2829
}
2930

30-
public void setCode(int code) {
31+
public void setCode(ResultStatus code) {
3132
this.code = code;
3233
}
3334

@@ -55,15 +56,15 @@ public void setCurrentTime(long currentTime) {
5556
this.currentTime = currentTime;
5657
}
5758

58-
public BaseResp(){}
59+
public BaseResp() {
60+
}
5961

6062
/**
61-
*
62-
* @param code 错误码
63+
* @param code 错误码
6364
* @param message 信息
64-
* @param data 数据
65+
* @param data 数据
6566
*/
66-
public BaseResp(int code, String message, T data) {
67+
public BaseResp(ResultStatus code, String message, T data) {
6768
this.code = code;
6869
this.message = message;
6970
this.data = data;
@@ -72,26 +73,50 @@ public BaseResp(int code, String message, T data) {
7273

7374
/**
7475
* 不带数据的返回结果
76+
*
7577
* @param resultStatus
7678
*/
7779
public BaseResp(ResultStatus resultStatus) {
78-
this.code = resultStatus.getErrorCode();
80+
this.code = resultStatus;
7981
this.message = resultStatus.getErrorMsg();
8082
this.currentTime = new Date().getTime();
8183
}
8284

8385
/**
8486
* 带数据的返回结果
87+
*
8588
* @param resultStatus
8689
* @param data
8790
*/
8891
public BaseResp(ResultStatus resultStatus, T data) {
89-
this.code = resultStatus.getErrorCode();
92+
this.code = resultStatus;
9093
this.message = resultStatus.getErrorMsg();
9194
this.data = data;
9295
this.currentTime = new Date().getTime();
9396
}
9497

98+
public static <T> BaseResp<T> success(T data, String msg) {
99+
BaseResp<T> response = new BaseResp<T>();
100+
response.setCode(ResultStatus.SUCCESS);
101+
response.setData(data);
102+
response.setMessage(msg);
103+
return response;
104+
}
105+
106+
public static BaseResp<String> fail(String msg) {
107+
BaseResp<String> response = new BaseResp<String>();
108+
response.setCode(ResultStatus.FAIL);
109+
response.setMessage(msg);
110+
return response;
111+
}
112+
113+
public static BaseResp<String> fail(ResultStatus code, String msg) {
114+
BaseResp<String> response = new BaseResp<String>();
115+
response.setCode(code);
116+
response.setMessage(msg);
117+
return response;
118+
}
119+
95120

96121
}
97122

quick-sample-server/sample-server/src/main/java/com/quick/utils/MyBatisPlusWithTemplateGenerator.java

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
11
package com.quick.utils;
22

3-
import com.baomidou.mybatisplus.annotation.FieldFill;
4-
import com.baomidou.mybatisplus.annotation.IdType;
53
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
64
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
7-
import com.baomidou.mybatisplus.generator.config.OutputFile;
5+
import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine;
86

97
import java.util.Arrays;
108
import java.util.Collections;
119
import java.util.List;
1210

13-
public class MyBatisPlusGenerator {
11+
public class MyBatisPlusWithTemplateGenerator {
1412

1513
public static final String OUT_DIR = "D:\\github\\spring-boot-quick\\quick-archetype\\src\\main\\java";
1614

17-
15+
1816
// 处理 all 情况
1917
protected static List<String> getTables(String tables) {
2018
return "all".equals(tables) ? Collections.emptyList() : Arrays.asList(tables.split(","));
2119
}
2220

2321
public static void main(String[] args) {
24-
FastAutoGenerator.create("jdbc:mysql://closnew-m.dbsit.sfcloud.local:3306/clos?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true", "clos", "aemycusn2g")
22+
FastAutoGenerator.create("", "", "")
2523
// 全局配置
2624
.globalConfig((scanner, builder) -> {
2725
builder.author(scanner.apply("请输入作者")).fileOverride();
@@ -35,7 +33,7 @@ public static void main(String[] args) {
3533
})
3634
// 策略配置
3735
.strategyConfig((scanner, builder) -> {
38-
builder.addInclude(MyBatisPlusGenerator.getTables(scanner.apply("请输入表名,多个英文逗号分隔?所有输入 all")))
36+
builder.addInclude(MyBatisPlusWithTemplateGenerator.getTables(scanner.apply("请输入表名,多个英文逗号分隔?所有输入 all")))
3937
.controllerBuilder()
4038
.enableRestStyle()
4139
.enableHyphenStyle()
@@ -63,6 +61,21 @@ public static void main(String[] args) {
6361
.enableBaseResultMap()
6462
.build();
6563
})
64+
.templateEngine(new VelocityTemplateEngine())
65+
.templateConfig(builder -> {
66+
builder.entity("/templates/entity.java.vm")
67+
.service("/templates/service.java.vm")
68+
.serviceImpl("/templates/serviceImpl.java.vm")
69+
.controller("/templates/controller.java.vm");
70+
})
71+
//注入配置————自定义模板
72+
.injectionConfig(builder -> builder
73+
.beforeOutputFile((tableInfo, objectMap) -> {
74+
System.out.println("tableInfo: " + tableInfo.getEntityName() + " objectMap: " + objectMap.size());
75+
}) //输出文件之前消费者
76+
.customMap(Collections.singletonMap("my_field", "自定义配置 Map 对象")) //自定义配置 Map 对象
77+
.customFile(Collections.singletonMap("query.java", "/templates/query.java.vm")) //自定义配置模板文件
78+
.build())//加入构建队列
6679
.execute();
6780
}
6881
}

0 commit comments

Comments
 (0)