Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
O
on-site-service
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
external
on-site-service
Commits
91333ecd
Commit
91333ecd
authored
Jul 06, 2022
by
shangtx
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: 代码生成器搬运
parent
82d7e46b
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
1120 additions
and
0 deletions
+1120
-0
pom.xml
pom.xml
+1
-0
pom.xml
test/pom.xml
+42
-0
ApiGenerator.java
test/src/main/java/com/onsiteservice/ApiGenerator.java
+255
-0
CodeGenerator.java
test/src/main/java/com/onsiteservice/CodeGenerator.java
+489
-0
MyJavaTypeResolverImpl.java
...c/main/java/com/onsiteservice/MyJavaTypeResolverImpl.java
+22
-0
controller-restful.ftl
test/src/main/resources/generator/controller-restful.ftl
+100
-0
controller-swagger.ftl
test/src/main/resources/generator/controller-swagger.ftl
+83
-0
mapper-xml.ftl
test/src/main/resources/generator/mapper-xml.ftl
+28
-0
mapper.ftl
test/src/main/resources/generator/mapper.ftl
+28
-0
service-impl.ftl
test/src/main/resources/generator/service-impl.ftl
+72
-0
No files found.
pom.xml
View file @
91333ecd
...
@@ -34,6 +34,7 @@
...
@@ -34,6 +34,7 @@
<module>
common
</module>
<module>
common
</module>
<module>
admin
</module>
<module>
admin
</module>
<module>
mini-app
</module>
<module>
mini-app
</module>
<module>
test
</module>
</modules>
</modules>
<dependencies>
<dependencies>
...
...
test/pom.xml
0 → 100644
View file @
91333ecd
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<artifactId>
parent
</artifactId>
<groupId>
com.onsiteservice
</groupId>
<version>
1.0.0
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
test
</artifactId>
<dependencies>
<!--依赖公共通用模块-->
<dependency>
<groupId>
com.onsiteservice
</groupId>
<artifactId>
common
</artifactId>
<version>
1.0.0
</version>
</dependency>
<!--代码生成器依赖-->
<dependency>
<groupId>
org.freemarker
</groupId>
<artifactId>
freemarker
</artifactId>
</dependency>
<dependency>
<groupId>
org.mybatis.generator
</groupId>
<artifactId>
mybatis-generator-core
</artifactId>
<version>
1.3.7
</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>
11
</maven.compiler.source>
<maven.compiler.target>
11
</maven.compiler.target>
</properties>
</project>
\ No newline at end of file
test/src/main/java/com/onsiteservice/ApiGenerator.java
0 → 100644
View file @
91333ecd
This diff is collapsed.
Click to expand it.
test/src/main/java/com/onsiteservice/CodeGenerator.java
0 → 100644
View file @
91333ecd
This diff is collapsed.
Click to expand it.
test/src/main/java/com/onsiteservice/MyJavaTypeResolverImpl.java
0 → 100644
View file @
91333ecd
package
com
.
onsiteservice
;
import
org.mybatis.generator.api.dom.java.FullyQualifiedJavaType
;
import
org.mybatis.generator.internal.types.JavaTypeResolverDefaultImpl
;
import
java.sql.Types
;
/**
* @author 潘维吉
* @date 2020-02-05 9:10
* 自定义Mybatis自动生成代码数据类型转换
*/
public
class
MyJavaTypeResolverImpl
extends
JavaTypeResolverDefaultImpl
{
public
MyJavaTypeResolverImpl
()
{
super
();
//把数据库的 TINYINT 映射成 Integer 类型 而不是Byte类型 简化程序开发
super
.
typeMap
.
put
(
Types
.
TINYINT
,
new
JdbcTypeInformation
(
"TINYINT"
,
new
FullyQualifiedJavaType
(
Integer
.
class
.
getName
())));
super
.
typeMap
.
put
(
Types
.
SMALLINT
,
new
JdbcTypeInformation
(
"SMALLINT"
,
new
FullyQualifiedJavaType
(
Integer
.
class
.
getName
())));
}
}
test/src/main/resources/generator/controller-restful.ftl
0 → 100644
View file @
91333ecd
<#
if
isGenFileModule
>
package
${
currentPackage
}.
controller
.${
fileModule
};
import
${
entityPackage
}.${
fileModule
}.${
modelNameUpperCamel
};
import
${
currentPackage
}.
service
.${
fileModule
}.${
modelNameUpperCamel
}
Service
;
<#
else
>
package
${
currentPackage
}.
controller
;
import
${
entityPackage
}.${
modelNameUpperCamel
};
import
${
currentPackage
}.
service
.${
modelNameUpperCamel
}
Service
;
</#
if
>
import
${
corePackage
}.
result
.
Result
;
import
${
commonDaoPackage
}.
common
.
page
.
PageParams
;
import
lombok
.
NonNull
;
import
org
.
springframework
.
validation
.
annotation
.
Validated
;
import
org
.
springframework
.
web
.
bind
.
annotation
.*;
import
javax
.
annotation
.
Resource
;
import
javax
.
validation
.
constraints
.
Positive
;
import
static
${
corePackage
}.
result
.
ResultGenerator
.
success
;
import
static
${
corePackage
}.
result
.
ResultGenerator
.
fail
;
/**
*
@
author
${
author
}
*
@
date
${
date
}
*
@
description
${
modelNameUpperCamel
}
Controller
控制类
*/
@
RestController
@
RequestMapping
(
"${requestMappingPath}"
)
@
Validated
public
class
${
modelNameUpperCamel
}
Controller
{
@
Resource
private
${
modelNameUpperCamel
}
Service
${
modelNameLowerCamel
}
Service
;
/**
*
分页查询列表
*
*
@
param
param
分页参数
*
@
return
分页数据
*/
@
PostMapping
(
"/page"
)
public
Result
getPage
(@
RequestBody
@
NonNull
@
Validated
PageParams
param
)
{
return
success
(${
modelNameLowerCamel
}
Service
.
getPage
(
param
),
"获取分页列表"
);
}
/**
*
根据
id
查询
*
*
@
param
id
主键
*
@
return
详情数据
*/
@
GetMapping
(
"/{id}"
)
public
Result
getDetails
(@
PathVariable
@
Positive
Long
id
)
{
return
success
(${
modelNameLowerCamel
}
Service
.
selectByPrimaryKey
(
id
),
"根据id获取详情"
);
}
<#
if
isGenSaveOrUpdate
>
/**
*
新增或修改
*/
@
PostMapping
(
"/save-or-update"
)
public
Result
saveOrUpdate
(@
RequestBody
@
NonNull
@
Validated
${
modelNameUpperCamel
}
${
modelNameLowerCamel
})
{
return
success
(${
modelNameLowerCamel
}
Service
.
saveOrUpdate
(${
modelNameLowerCamel
}),
${
modelNameLowerCamel
}.
getId
()
==
null
?
"新增成功"
:
"修改成功"
);
}
<#
else
>
/**
*
新增
*
*
@
param
${
modelNameLowerCamel
}
新增对象
*/
@
PostMapping
public
Result
save
(@
RequestBody
@
NonNull
@
Validated
${
modelNameUpperCamel
}
${
modelNameLowerCamel
})
{
return
success
(${
modelNameLowerCamel
}
Service
.
insertSelective
(${
modelNameLowerCamel
}),
"新增成功"
);
}
/**
*
修改
*
*
@
param
${
modelNameLowerCamel
}
修改对象
*/
@
PutMapping
public
Result
update
(@
RequestBody
@
NonNull
@
Validated
${
modelNameUpperCamel
}
${
modelNameLowerCamel
})
{
return
success
(${
modelNameLowerCamel
}
Service
.
updateByPrimaryKeySelective
(${
modelNameLowerCamel
}),
"修改成功"
);
}
</#
if
>
/**
*
根据
id
删除
*
*
@
param
id
主键
*/
@
DeleteMapping
(
"/{id}"
)
public
Result
deleteById
(@
PathVariable
@
Positive
Long
id
)
{
return
success
(${
modelNameLowerCamel
}
Service
.
deleteByPrimaryKey
(
id
),
"删除成功"
);
}
}
test/src/main/resources/generator/controller-swagger.ftl
0 → 100644
View file @
91333ecd
<#
if
isGenFileModule
>
package
${
currentPackage
}.
controller
.${
fileModule
};
import
${
entityPackage
}.${
fileModule
}.${
modelNameUpperCamel
};
import
${
currentPackage
}.
service
.${
fileModule
}.${
modelNameUpperCamel
}
Service
;
<#
else
>
package
${
currentPackage
}.
controller
;
import
${
daoPackage
}.
model
.${
modelNameUpperCamel
};
import
${
currentPackage
}.
service
.${
modelNameUpperCamel
}
Service
;
</#
if
>
import
${
corePackage
}.
result
.
Result
;
import
${
commonDaoPackage
}.
common
.
page
.
PageInfoVO
;
import
${
commonDaoPackage
}.
common
.
page
.
PageParams
;
import
io
.
swagger
.
annotations
.
Api
;
import
io
.
swagger
.
annotations
.
ApiOperation
;
import
lombok
.
NonNull
;
import
org
.
springframework
.
validation
.
annotation
.
Validated
;
import
org
.
springframework
.
web
.
bind
.
annotation
.*;
import
springfox
.
documentation
.
annotations
.
ApiIgnore
;
import
javax
.
annotation
.
Resource
;
import
javax
.
validation
.
constraints
.
Positive
;
import
static
${
corePackage
}.
result
.
ResultGenerator
.
success
;
import
static
${
corePackage
}.
result
.
ResultGenerator
.
fail
;
/**
*
@
author
${
author
}
*
@
date
${
date
}
*
@
description
${
modelNameUpperCamel
}
Controller
控制类
*/
@
ApiIgnore
@
Api
(
tags
=
"${modelNameUpperCamel}Controller"
)
@
RestController
@
RequestMapping
(
"${requestMappingPath}"
)
@
Validated
public
class
${
modelNameUpperCamel
}
Controller
{
@
Resource
private
${
modelNameUpperCamel
}
Service
${
modelNameLowerCamel
}
Service
;
@
ApiOperation
(
value
=
"分页查询列表"
,
notes
=
"作者: ${author}"
)
@
PostMapping
(
"/page"
)
public
Result
<
PageInfoVO
>
getPage
(@
RequestBody
@
NonNull
@
Validated
PageParams
param
)
{
return
success
(${
modelNameLowerCamel
}
Service
.
getPage
(
param
),
"获取分页列表"
);
}
@
ApiOperation
(
value
=
"根据id查询"
,
notes
=
"作者: ${author}"
)
@
GetMapping
(
"/{id}"
)
public
Result
<${
modelNameUpperCamel
}>
getDetails
(@
PathVariable
@
Positive
Long
id
)
{
return
success
(${
modelNameLowerCamel
}
Service
.
selectByPrimaryKey
(
id
),
"根据id获取详情"
);
}
<#
if
isGenSaveOrUpdate
>
@
ApiOperation
(
value
=
"新增或修改"
,
notes
=
"作者: ${author}"
)
@
PostMapping
(
"/save-or-update"
)
public
Result
saveOrUpdate
(@
RequestBody
@
NonNull
@
Validated
${
modelNameUpperCamel
}
${
modelNameLowerCamel
})
{
return
success
(${
modelNameLowerCamel
}
Service
.
saveOrUpdate
(${
modelNameLowerCamel
}),
${
modelNameLowerCamel
}.
getId
()
==
null
?
"新增成功"
:
"修改成功"
);
}
<#
else
>
@
ApiOperation
(
value
=
"新增"
,
notes
=
"作者: ${author}"
)
@
PostMapping
public
Result
save
(@
RequestBody
@
NonNull
@
Validated
${
modelNameUpperCamel
}
${
modelNameLowerCamel
})
{
return
success
(${
modelNameLowerCamel
}
Service
.
insertSelective
(${
modelNameLowerCamel
}),
"新增成功"
);
}
@
ApiOperation
(
value
=
"修改"
,
notes
=
"作者: ${author}"
)
@
PutMapping
public
Result
update
(@
RequestBody
@
NonNull
@
Validated
${
modelNameUpperCamel
}
${
modelNameLowerCamel
})
{
return
success
(${
modelNameLowerCamel
}
Service
.
updateByPrimaryKeySelective
(${
modelNameLowerCamel
}),
"修改成功"
);
}
</#
if
>
@
ApiOperation
(
value
=
"根据id删除"
,
notes
=
"作者: ${author}"
)
@
DeleteMapping
(
"/{id}"
)
public
Result
deleteById
(@
PathVariable
@
Positive
Long
id
)
{
return
success
(${
modelNameLowerCamel
}
Service
.
deleteByPrimaryKey
(
id
),
"删除成功"
);
}
}
test/src/main/resources/generator/mapper-xml.ftl
0 → 100644
View file @
91333ecd
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<
#if isGenFileModule >
<mapper
namespace=
"${currentPackage}.mapper.${fileModule}.${modelNameUpperCamel}BizMapper"
>
<
#else>
<mapper
namespace=
"${currentPackage}.mapper.${modelNameUpperCamel}BizMapper"
>
<
/#if>
<
#if isGenPage >
<!--分页查询列表-->
<select
id=
"getPage"
resultType=
"map"
>
select t1.*
from t1
<where>
and t1.is_deleted = 0
<if
test=
"param.name != null and param.name != ''"
>
and t1.name like
<
#noparse>"%"#{param.name}"%"
<
/#noparse>
</if>
</where>
order by
<if
test=
"param.sort != null and param.sort != ''"
>
<
#noparse>${param.sort} ${param.order}
<
/#noparse>,
</if>
t1.id desc
</select>
<
/#if>
</mapper>
test/src/main/resources/generator/mapper.ftl
0 → 100644
View file @
91333ecd
<#
if
isGenFileModule
>
package
${
currentPackage
}.
mapper
.${
fileModule
};
<#
else
>
package
${
currentPackage
}.
mapper
;
</#
if
>
<#
if
isGenPage
>
import
${
commonDaoPackage
}.
common
.
page
.
PageParams
;
import
org
.
apache
.
ibatis
.
annotations
.
Param
;
import
java
.
util
.
List
;
</#
if
>
/**
*
@
author
${
author
}
*
@
date
${
date
}
*
@
description
${
modelNameUpperCamel
}
BizMapper
业务接口
*/
public
interface
${
modelNameUpperCamel
}
BizMapper
{
<#
if
isGenPage
>
/**
*
分页查询列表
*/
List
getPage
(@
Param
(
"param"
)
PageParams
param
);
</#
if
>
}
test/src/main/resources/generator/service-impl.ftl
0 → 100644
View file @
91333ecd
<#
if
isGenFileModule
>
package
${
currentPackage
}.
service
.${
fileModule
};
import
${
entityPackage
}.${
fileModule
}.${
modelNameUpperCamel
};
<#
if
isGenMapperSeparate
>
import
${
daoPackage
}.
mapper
.${
fileModule
}.${
modelNameUpperCamel
}
Mapper
;
import
${
currentPackage
}.
mapper
.${
fileModule
}.${
modelNameUpperCamel
}
BizMapper
;
<#
else
>
import
${
currentPackage
}.
mapper
.${
fileModule
}.${
modelNameUpperCamel
}
Mapper
;
</#
if
>
<#
else
>
package
${
currentPackage
}.
service
;
import
${
entityPackage
}.${
modelNameUpperCamel
};
<#
if
isGenMapperSeparate
>
import
${
daoPackage
}.
mapper
.${
modelNameUpperCamel
}
Mapper
;
import
${
currentPackage
}.
mapper
.${
modelNameUpperCamel
}
BizMapper
;
<#
else
>
import
${
currentPackage
}.
mapper
.${
modelNameUpperCamel
}
Mapper
;
</#
if
>
</#
if
>
import
${
commonDaoPackage
}.
common
.
AbstractMapper
;
import
${
commonDaoPackage
}.
common
.
page
.
PageParams
;
import
${
commonDaoPackage
}.
common
.
page
.
PageInfoVO
;
import
com
.
github
.
pagehelper
.
PageHelper
;
import
org
.
springframework
.
stereotype
.
Service
;
import
org
.
springframework
.
transaction
.
annotation
.
Transactional
;
import
javax
.
annotation
.
Resource
;
/**
*
@
author
${
author
}
*
@
date
${
date
}
*
@
description
${
modelNameUpperCamel
}
Service
服务类
*/
@
Service
@
Transactional
(
rollbackFor
=
Exception
.
class
)
public
class
${
modelNameUpperCamel
}
Service
extends
AbstractMapper
<${
modelNameUpperCamel
}>
{
@
Resource
private
${
modelNameUpperCamel
}
Mapper
${
modelNameLowerCamel
}
Mapper
;
<#
if
isGenMapperSeparate
>
@
Resource
private
${
modelNameUpperCamel
}
BizMapper
${
modelNameLowerCamel
}
BizMapper
;
</#
if
>
/**
*
分页查询列表
*/
public
PageInfoVO
getPage
(
PageParams
param
)
{
PageHelper
.
startPage
(
param
.
getPage
(),
param
.
getSize
());
<#
if
!isGenPage >
return
new
PageInfoVO
(
this
.
selectAll
());
<#
else
>
return
new
PageInfoVO
(${
modelNameLowerCamel
}
BizMapper
.
getPage
(
param
));
</#
if
>
}
<#
if
isGenSaveOrUpdate
>
/**
*
保存或更新方法
*/
public
int
saveOrUpdate
(${
modelNameUpperCamel
}
${
modelNameLowerCamel
})
{
if
(${
modelNameLowerCamel
}.
getId
()
==
null
)
{
return
this
.
insertSelective
(${
modelNameLowerCamel
});
}
else
{
return
this
.
updateByPrimaryKeySelective
(${
modelNameLowerCamel
});
}
}
</#
if
>
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment