Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qq_41234584
spring-boot-demo
提交
4c2e51d0
S
spring-boot-demo
项目概览
qq_41234584
/
spring-boot-demo
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-boot-demo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
4c2e51d0
编写于
8月 30, 2020
作者:
Y
yanshaoshuai
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修改mapper.xml文件生成格式-->实现jdbcType无须手动修改
上级
9b9a24d7
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
136 addition
and
36 deletion
+136
-36
spring-boot-demo-codegen/pom.xml
spring-boot-demo-codegen/pom.xml
+0
-7
spring-boot-demo-codegen/src/main/java/com/xkcoding/codegen/entity/ColumnEntity.java
...c/main/java/com/xkcoding/codegen/entity/ColumnEntity.java
+4
-0
spring-boot-demo-codegen/src/main/java/com/xkcoding/codegen/utils/CodeGenUtil.java
...src/main/java/com/xkcoding/codegen/utils/CodeGenUtil.java
+13
-9
spring-boot-demo-codegen/src/main/resources/jdbc_type.properties
...boot-demo-codegen/src/main/resources/jdbc_type.properties
+21
-0
spring-boot-demo-codegen/src/main/resources/logback-spring.xml
...g-boot-demo-codegen/src/main/resources/logback-spring.xml
+79
-0
spring-boot-demo-codegen/src/main/resources/template/Controller.java.vm
...mo-codegen/src/main/resources/template/Controller.java.vm
+11
-15
spring-boot-demo-codegen/src/main/resources/template/Entity.java.vm
...t-demo-codegen/src/main/resources/template/Entity.java.vm
+4
-2
spring-boot-demo-codegen/src/main/resources/template/Mapper.xml.vm
...ot-demo-codegen/src/main/resources/template/Mapper.xml.vm
+2
-2
spring-boot-demo-codegen/src/main/resources/template/ServiceImpl.java.vm
...o-codegen/src/main/resources/template/ServiceImpl.java.vm
+2
-1
未找到文件。
spring-boot-demo-codegen/pom.xml
浏览文件 @
4c2e51d0
...
...
@@ -9,13 +9,6 @@
<name>
spring-boot-demo-codegen
</name>
<description>
Demo project for Spring Boot
</description>
<parent>
<groupId>
com.xkcoding
</groupId>
<artifactId>
spring-boot-demo
</artifactId>
<version>
1.0.0-SNAPSHOT
</version>
</parent>
<properties>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<project.reporting.outputEncoding>
UTF-8
</project.reporting.outputEncoding>
...
...
spring-boot-demo-codegen/src/main/java/com/xkcoding/codegen/entity/ColumnEntity.java
浏览文件 @
4c2e51d0
...
...
@@ -41,6 +41,10 @@ public class ColumnEntity {
* 属性类型
*/
private
String
attrType
;
/**
* jdbc类型
*/
private
String
jdbcType
;
/**
* 其他信息
*/
...
...
spring-boot-demo-codegen/src/main/java/com/xkcoding/codegen/utils/CodeGenUtil.java
浏览文件 @
4c2e51d0
...
...
@@ -69,7 +69,9 @@ public class CodeGenUtil {
*/
public
void
generatorCode
(
GenConfig
genConfig
,
Entity
table
,
List
<
Entity
>
columns
,
ZipOutputStream
zip
)
{
//配置信息
Props
props
=
getConfig
();
Props
propsDB2Java
=
getConfig
(
"generator.properties"
);
Props
propsDB2Jdbc
=
getConfig
(
"jdbc_type.properties"
);
boolean
hasBigDecimal
=
false
;
//表信息
TableEntity
tableEntity
=
new
TableEntity
();
...
...
@@ -85,7 +87,7 @@ public class CodeGenUtil {
if
(
StrUtil
.
isNotBlank
(
genConfig
.
getTablePrefix
()))
{
tablePrefix
=
genConfig
.
getTablePrefix
();
}
else
{
tablePrefix
=
props
.
getStr
(
"tablePrefix"
);
tablePrefix
=
props
DB2Java
.
getStr
(
"tablePrefix"
);
}
//表名转换成Java类名
...
...
@@ -108,8 +110,10 @@ public class CodeGenUtil {
columnEntity
.
setLowerAttrName
(
StrUtil
.
lowerFirst
(
attrName
));
//列的数据类型,转换成Java类型
String
attrType
=
props
.
getStr
(
columnEntity
.
getDataType
(),
"unknownType"
);
String
attrType
=
props
DB2Java
.
getStr
(
columnEntity
.
getDataType
(),
"unknownType"
);
columnEntity
.
setAttrType
(
attrType
);
String
jdbcType
=
propsDB2Jdbc
.
getStr
(
columnEntity
.
getDataType
(),
"unknownType"
);
columnEntity
.
setJdbcType
(
jdbcType
);
if
(!
hasBigDecimal
&&
"BigDecimal"
.
equals
(
attrType
))
{
hasBigDecimal
=
true
;
}
...
...
@@ -152,21 +156,21 @@ public class CodeGenUtil {
if
(
StrUtil
.
isNotBlank
(
genConfig
.
getAuthor
()))
{
map
.
put
(
"author"
,
genConfig
.
getAuthor
());
}
else
{
map
.
put
(
"author"
,
props
.
getStr
(
"author"
));
map
.
put
(
"author"
,
props
DB2Java
.
getStr
(
"author"
));
}
if
(
StrUtil
.
isNotBlank
(
genConfig
.
getModuleName
()))
{
map
.
put
(
"moduleName"
,
genConfig
.
getModuleName
());
}
else
{
map
.
put
(
"moduleName"
,
props
.
getStr
(
"moduleName"
));
map
.
put
(
"moduleName"
,
props
DB2Java
.
getStr
(
"moduleName"
));
}
if
(
StrUtil
.
isNotBlank
(
genConfig
.
getPackageName
()))
{
map
.
put
(
"package"
,
genConfig
.
getPackageName
());
map
.
put
(
"mainPath"
,
genConfig
.
getPackageName
());
}
else
{
map
.
put
(
"package"
,
props
.
getStr
(
"package"
));
map
.
put
(
"mainPath"
,
props
.
getStr
(
"mainPath"
));
map
.
put
(
"package"
,
props
DB2Java
.
getStr
(
"package"
));
map
.
put
(
"mainPath"
,
props
DB2Java
.
getStr
(
"mainPath"
));
}
VelocityContext
context
=
new
VelocityContext
(
map
);
...
...
@@ -213,8 +217,8 @@ public class CodeGenUtil {
/**
* 获取配置信息
*/
private
Props
getConfig
()
{
Props
props
=
new
Props
(
"generator.properties"
);
private
Props
getConfig
(
String
fileName
)
{
Props
props
=
new
Props
(
fileName
);
props
.
autoLoad
(
true
);
return
props
;
}
...
...
spring-boot-demo-codegen/src/main/resources/jdbc_type.properties
0 → 100644
浏览文件 @
4c2e51d0
tinyint
=
TINYINT
smallint
=
SMALLINT
mediumint
=
MEDIUMINT
int
=
INTEGER
integer
=
INTEGER
bigint
=
BIGINT
float
=
FLOAT
double
=
DOUBLE
decimal
=
DECIMAL
bit
=
BIT
char
=
CHAR
varchar
=
VARCHAR
tinytext
=
VARCHAR
text
=
VARCHAR
mediumtext
=
VARCHAR
longtext
=
VARCHAR
date
=
DATE
datetime
=
DATETIME
timestamp
=
TIMESTAMP
blob
=
BLOB
longblob
=
LONGBLOB
spring-boot-demo-codegen/src/main/resources/logback-spring.xml
0 → 100644
浏览文件 @
4c2e51d0
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property
name=
"FILE_ERROR_PATTERN"
value=
"${FILE_LOG_PATTERN:-%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}} ${LOG_LEVEL_PATTERN:-%5p} ${PID:- } --- [%t] %-40.40logger{39} %file:%line: %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"
/>
<include
resource=
"org/springframework/boot/logging/logback/defaults.xml"
/>
<appender
name=
"CONSOLE"
class=
"ch.qos.logback.core.ConsoleAppender"
>
<filter
class=
"ch.qos.logback.classic.filter.LevelFilter"
>
<level>
INFO
</level>
</filter>
<encoder>
<pattern>
${CONSOLE_LOG_PATTERN}
</pattern>
<charset>
UTF-8
</charset>
</encoder>
</appender>
<appender
name=
"FILE_INFO"
class=
"ch.qos.logback.core.rolling.RollingFileAppender"
>
<!--如果只是想要 Info 级别的日志,只是过滤 info 还是会输出 Error 日志,因为 Error 的级别高, 所以我们使用下面的策略,可以避免输出 Error 的日志-->
<filter
class=
"ch.qos.logback.classic.filter.LevelFilter"
>
<!--过滤 Error-->
<level>
ERROR
</level>
<!--匹配到就禁止-->
<onMatch>
DENY
</onMatch>
<!--没有匹配到就允许-->
<onMismatch>
ACCEPT
</onMismatch>
</filter>
<!--日志名称,如果没有File 属性,那么只会使用FileNamePattern的文件路径规则如果同时有<File>和<FileNamePattern>,那么当天日志是<File>,明天会自动把今天的日志改名为今天的日期。即,<File> 的日志都是当天的。-->
<!--<File>logs/info.spring-boot-demo-logback.log</File>-->
<!--滚动策略,按照时间滚动 TimeBasedRollingPolicy-->
<rollingPolicy
class=
"ch.qos.logback.core.rolling.TimeBasedRollingPolicy"
>
<!--文件路径,定义了日志的切分方式——把每一天的日志归档到一个文件中,以防止日志填满整个磁盘空间-->
<FileNamePattern>
logs/spring-boot-demo-logback/info.created_on_%d{yyyy-MM-dd}.part_%i.log
</FileNamePattern>
<!--只保留最近90天的日志-->
<maxHistory>
90
</maxHistory>
<!--用来指定日志文件的上限大小,那么到了这个值,就会删除旧的日志-->
<!--<totalSizeCap>1GB</totalSizeCap>-->
<timeBasedFileNamingAndTriggeringPolicy
class=
"ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"
>
<!-- maxFileSize:这是活动文件的大小,默认值是10MB,本篇设置为1KB,只是为了演示 -->
<maxFileSize>
2MB
</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<!--<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">-->
<!--<maxFileSize>1KB</maxFileSize>-->
<!--</triggeringPolicy>-->
<encoder>
<pattern>
${FILE_LOG_PATTERN}
</pattern>
<charset>
UTF-8
</charset>
<!-- 此处设置字符集 -->
</encoder>
</appender>
<appender
name=
"FILE_ERROR"
class=
"ch.qos.logback.core.rolling.RollingFileAppender"
>
<!--如果只是想要 Error 级别的日志,那么需要过滤一下,默认是 info 级别的,ThresholdFilter-->
<filter
class=
"ch.qos.logback.classic.filter.ThresholdFilter"
>
<level>
Error
</level>
</filter>
<!--日志名称,如果没有File 属性,那么只会使用FileNamePattern的文件路径规则如果同时有<File>和<FileNamePattern>,那么当天日志是<File>,明天会自动把今天的日志改名为今天的日期。即,<File> 的日志都是当天的。-->
<!--<File>logs/error.spring-boot-demo-logback.log</File>-->
<!--滚动策略,按照时间滚动 TimeBasedRollingPolicy-->
<rollingPolicy
class=
"ch.qos.logback.core.rolling.TimeBasedRollingPolicy"
>
<!--文件路径,定义了日志的切分方式——把每一天的日志归档到一个文件中,以防止日志填满整个磁盘空间-->
<FileNamePattern>
logs/spring-boot-demo-logback/error.created_on_%d{yyyy-MM-dd}.part_%i.log
</FileNamePattern>
<!--只保留最近90天的日志-->
<maxHistory>
90
</maxHistory>
<timeBasedFileNamingAndTriggeringPolicy
class=
"ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"
>
<!-- maxFileSize:这是活动文件的大小,默认值是10MB,本篇设置为1KB,只是为了演示 -->
<maxFileSize>
2MB
</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder>
<pattern>
${FILE_ERROR_PATTERN}
</pattern>
<charset>
UTF-8
</charset>
<!-- 此处设置字符集 -->
</encoder>
</appender>
<root
level=
"info"
>
<appender-ref
ref=
"CONSOLE"
/>
<appender-ref
ref=
"FILE_INFO"
/>
<appender-ref
ref=
"FILE_ERROR"
/>
</root>
</configuration>
spring-boot-demo-codegen/src/main/resources/template/Controller.java.vm
浏览文件 @
4c2e51d0
...
...
@@ -2,17 +2,16 @@ package ${package}.${moduleName}.controller;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xkcoding.common.R;
import com.xkcoding.scaffold.log.annotations.ApiLog;
import
${
package
}
.
${
moduleName
}
.common.R;
import
${
package
}
.
${
moduleName
}
.entity.
${
className
}
;
import
${
package
}
.
${
moduleName
}
.service.
${
className
}
Service;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import lombok.extern.slf4j.Slf4j;
/**
*
<p>
*
${
comments
}
...
...
@@ -26,13 +25,13 @@ import io.swagger.annotations.ApiImplicitParams;
* @version: V1.0
* @modified:
${
author
}
*/
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/
${
pathName
}
")
@Api(description = "
${
className
}
Controller", tags =
{
"
${
comments
}
"})
public class
${
className
}
Controller
{
private
final
${
className
}
Service
${
classname
}
Service;
@Autowired
private
${
className
}
Service
${
classname
}
Service;
/**
* 分页查询
${
comments
}
...
...
@@ -47,7 +46,7 @@ public class ${className}Controller {
@ApiImplicitParam(name = "
${
classname
}
", value = "查询条件", required = true)
})
public R list
${
className
}
(Page page,
${
className
}
${
classname
}
)
{
return
new R
<>
(
${
classname
}
Service.page(page,Wrappers.query(
${
classname
}
)));
return
R.success
(
${
classname
}
Service.page(page,Wrappers.query(
${
classname
}
)));
}
...
...
@@ -62,7 +61,7 @@ public class ${className}Controller {
@ApiImplicitParam(name = "
${
pk
.
lowerAttrName
}
", value = "主键id", required = true)
})
public R get
${
className
}
(@PathVariable("
${
pk
.
lowerAttrName
}
")
${
pk
.
attrType
}
${
pk
.
lowerAttrName
}
)
{
return
new R
<>
(
${
classname
}
Service.getById(
${
pk
.
lowerAttrName
}
));
return
R.success
(
${
classname
}
Service.getById(
${
pk
.
lowerAttrName
}
));
}
/**
...
...
@@ -70,11 +69,10 @@ public class ${className}Controller {
* @param
${
classname
}
${
comments
}
* @return R
*/
@ApiLog("新增
${
comments
}
")
@PostMapping
@ApiOperation(value = "新增
${
comments
}
", notes = "新增
${
comments
}
")
public R save
${
className
}
(@RequestBody
${
className
}
${
classname
}
)
{
return
new R
<>
(
${
classname
}
Service.save(
${
classname
}
));
return
R.success
(
${
classname
}
Service.save(
${
classname
}
));
}
/**
...
...
@@ -83,14 +81,13 @@ public class ${className}Controller {
* @param
${
classname
}
${
comments
}
* @return R
*/
@ApiLog("修改
${
comments
}
")
@PutMapping("/
{
${
pk
.
lowerAttrName
}
}")
@ApiOperation(value = "修改
${
comments
}
", notes = "修改
${
comments
}
")
@ApiImplicitParams(
{
@ApiImplicitParam(name = "
${
pk
.
lowerAttrName
}
", value = "主键id", required = true)
})
public R update
${
className
}
(@PathVariable
${
pk
.
attrType
}
${
pk
.
lowerAttrName
}
, @RequestBody
${
className
}
${
classname
}
)
{
return
new R
<>
(
${
classname
}
Service.updateById(
${
classname
}
));
return
R.success
(
${
classname
}
Service.updateById(
${
classname
}
));
}
/**
...
...
@@ -98,14 +95,13 @@ public class ${className}Controller {
* @param
${
pk
.
lowerAttrName
}
id
* @return R
*/
@ApiLog("删除
${
comments
}
")
@DeleteMapping("/
{
${
pk
.
lowerAttrName
}
}")
@ApiOperation(value = "删除
${
comments
}
", notes = "删除
${
comments
}
")
@ApiImplicitParams(
{
@ApiImplicitParam(name = "
${
pk
.
lowerAttrName
}
", value = "主键id", required = true)
})
public R delete
${
className
}
(@PathVariable
${
pk
.
attrType
}
${
pk
.
lowerAttrName
}
)
{
return
new R
<>
(
${
classname
}
Service.removeById(
${
pk
.
lowerAttrName
}
));
return
R.success
(
${
classname
}
Service.removeById(
${
pk
.
lowerAttrName
}
));
}
}
spring-boot-demo-codegen/src/main/resources/template/Entity.java.vm
浏览文件 @
4c2e51d0
...
...
@@ -8,9 +8,10 @@ import lombok.EqualsAndHashCode;
#
if
(${
hasBigDecimal
})
import java.math.BigDecimal;
#
end
import java.io.Serializable;
import java.time.LocalDateTime;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.NoArgsConstructor;
/**
*
<p>
*
${
comments
}
...
...
@@ -25,6 +26,7 @@ import java.time.LocalDateTime;
* @modified:
${
author
}
*/
@Data
@NoArgsConstructor
@TableName("
${
tableName
}
")
@ApiModel(description = "
${
comments
}
")
@EqualsAndHashCode(callSuper = true)
...
...
spring-boot-demo-codegen/src/main/resources/template/Mapper.xml.vm
浏览文件 @
4c2e51d0
...
...
@@ -4,9 +4,9 @@
<resultMap
id=
"
${
classname
}
Map"
type=
"
${
package
}
.
${
moduleName
}
.entity.
${
className
}
"
>
#
foreach
($
column
in
$
columns
)
#
if
($
column
.
lowerAttrName
==
$
pk
.
lowerAttrName
)
<id
property=
"
${
pk
.
lowerAttrName
}
"
jdbcType=
"
${
pk
.
data
Type
}
"
column=
"
${
pk
.
columnName
}
"
/>
<id
property=
"
${
pk
.
lowerAttrName
}
"
jdbcType=
"
${
pk
.
jdbc
Type
}
"
column=
"
${
pk
.
columnName
}
"
/>
#
else
<result
property=
"
${
column
.
lowerAttrName
}
"
jdbcType=
"
${
column
.
data
Type
}
"
column=
"
${
column
.
columnName
}
"
/>
<result
property=
"
${
column
.
lowerAttrName
}
"
jdbcType=
"
${
column
.
jdbc
Type
}
"
column=
"
${
column
.
columnName
}
"
/>
#
end
#
end
</resultMap>
...
...
spring-boot-demo-codegen/src/main/resources/template/ServiceImpl.java.vm
浏览文件 @
4c2e51d0
...
...
@@ -5,7 +5,7 @@ import ${package}.${moduleName}.entity.${className};
import
${
package
}
.
${
moduleName
}
.mapper.
${
className
}
Mapper;
import
${
package
}
.
${
moduleName
}
.service.
${
className
}
Service;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;
/**
*
<p>
*
${
comments
}
...
...
@@ -20,6 +20,7 @@ import org.springframework.stereotype.Service;
* @modified:
${
author
}
*/
@Service
@Slf4j
public class
${
className
}
ServiceImpl extends ServiceImpl
<
${
className
}
Mapper
,
${
className
}
>
implements
${
className
}
Service
{
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录