Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
ydl-generator
Overview
Overview
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
余保谷
ydl-generator
Commits
0e69ee74
Commit
0e69ee74
authored
Aug 10, 2018
by
bianpeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
2.0.0
parent
434266a5
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
58 additions
and
46 deletions
+58
-46
pom.xml
pom.xml
+2
-2
BasisInfo.java
src/main/java/com/github/mybatis/entity/BasisInfo.java
+4
-0
TestMain.java
src/main/java/com/github/mybatis/test/TestMain.java
+21
-21
EntityInfoUtil.java
src/main/java/com/github/mybatis/util/EntityInfoUtil.java
+9
-1
controller.ftl
src/main/resources/freemarker/ftl/controller.ftl
+9
-9
dao.ftl
src/main/resources/freemarker/ftl/dao.ftl
+2
-2
mapper.ftl
src/main/resources/freemarker/ftl/mapper.ftl
+7
-7
service.ftl
src/main/resources/freemarker/ftl/service.ftl
+2
-2
serviceImpl.ftl
src/main/resources/freemarker/ftl/serviceImpl.ftl
+2
-2
No files found.
pom.xml
View file @
0e69ee74
...
...
@@ -3,9 +3,9 @@
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
com.github
</groupId>
<groupId>
com.github
.flying-cattle
</groupId>
<artifactId>
mybatis-dsc-generator
</artifactId>
<version>
1.1.6
.RELEASE
</version>
<version>
2.0.0
.RELEASE
</version>
<packaging>
jar
</packaging>
<name>
mybatis-dsc-generator
</name>
...
...
src/main/java/com/github/mybatis/entity/BasisInfo.java
View file @
0e69ee74
...
...
@@ -51,6 +51,10 @@ public class BasisInfo implements Serializable{
private
String
controllerUrl
;
private
String
idType
;
private
String
idJdbcType
;
private
List
<
PropertyInfo
>
cis
;
public
BasisInfo
(
String
project
,
String
author
,
String
version
,
String
dbUrl
,
String
dbName
,
String
dbPassword
,
...
...
src/main/java/com/github/mybatis/test/TestMain.java
View file @
0e69ee74
...
...
@@ -10,27 +10,27 @@ import com.github.mybatis.util.MySqlToJavaUtil;
public
class
TestMain
{
//基础信息
public
static
final
String
PROJECT
=
"
deal-center
"
;
public
static
final
String
PROJECT
=
"
qixingbao-show
"
;
public
static
final
String
AUTHOR
=
"BianP"
;
public
static
final
String
VERSION
=
"V1.0"
;
//数据库连接信息
public
static
final
String
URL
=
"jdbc:mysql://127.0.0.1:3306/
xin
?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&failOverReadOnly=false&useSSL=true"
;
public
static
final
String
URL
=
"jdbc:mysql://127.0.0.1:3306/
qixingbao
?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&failOverReadOnly=false&useSSL=true"
;
public
static
final
String
NAME
=
"root"
;
public
static
final
String
PASSWORD
=
"123456"
;
public
static
final
String
DATABASE
=
"
xin
"
;
public
static
final
String
DATABASE
=
"
qixingbao
"
;
//类信息
public
static
final
String
TABLE
=
"
user
"
;
public
static
final
String
CLASSNAME
=
"
User
"
;
public
static
final
String
CLASSCOMMENT
=
"
用户信息
"
;
public
static
final
String
TIME
=
"2018年
6月30
日"
;
public
static
final
String
TABLE
=
"
product
"
;
public
static
final
String
CLASSNAME
=
"
Product
"
;
public
static
final
String
CLASSCOMMENT
=
"
产品
"
;
public
static
final
String
TIME
=
"2018年
7月5
日"
;
public
static
final
String
AGILE
=
new
Date
().
getTime
()+
""
;
//路径信息
public
static
final
String
ENTITY_URL
=
"com.
xin.dealcenter
.entity"
;
public
static
final
String
DAO_URL
=
"com.
xin.dealcenter
.dao"
;
public
static
final
String
XML_URL
=
"com.
xin.dealcenter
.dao.impl"
;
public
static
final
String
SERVICE_URL
=
"com.
xin.dealcenter
.service"
;
public
static
final
String
SERVICE_IMPL_URL
=
"com.
xin.dealcenter
.service.impl"
;
public
static
final
String
CONTROLLER_URL
=
"com.
xin.dealcenter
.webApi"
;
public
static
final
String
ENTITY_URL
=
"com.
qixingbao.show
.entity"
;
public
static
final
String
DAO_URL
=
"com.
qixingbao.show
.dao"
;
public
static
final
String
XML_URL
=
"com.
qixingbao.show
.dao.impl"
;
public
static
final
String
SERVICE_URL
=
"com.
qixingbao.show
.service"
;
public
static
final
String
SERVICE_IMPL_URL
=
"com.
qixingbao.show
.service.impl"
;
public
static
final
String
CONTROLLER_URL
=
"com.
qixingbao.show
.webApi"
;
public
static
void
main
(
String
[]
args
)
{
...
...
@@ -41,19 +41,19 @@ public class TestMain {
bi
.
setEntityComment
(
CLASSCOMMENT
);
try
{
bi
=
EntityInfoUtil
.
getInfo
(
bi
);
String
aa1
=
Generator
.
createEntity
(
"E:\\
test_workspace\\mybatis-generator
\\src\\main\\java\\"
,
bi
).
toString
();
/*String aa2=Generator.createDao("E:\\test_workspace\\mybatis-generator
\\src\\main\\java\\", bi).toString();
String aa3=Generator.createDaoImpl("E:\\
test_workspace\\mybatis-generator
\\src\\main\\java\\", bi).toString();
String aa4=Generator.createService("E:\\
test_workspace\\mybatis-generator
\\src\\main\\java\\", bi).toString();
String aa5=Generator.createServiceImpl("E:\\
test_workspace\\mybatis-generator
\\src\\main\\java\\", bi).toString();
String aa6=Generator.createController("E:\\
test_workspace\\mybatis-generator\\src\\main\\java\\", bi).toString();*/
String
aa1
=
Generator
.
createEntity
(
"E:\\
A-ZM-work\\work_qxb2\\qxbplatform\\qixingbao-show
\\src\\main\\java\\"
,
bi
).
toString
();
String
aa2
=
Generator
.
createDao
(
"E:\\A-ZM-work\\work_qxb2\\qxbplatform\\qixingbao-show
\\src\\main\\java\\"
,
bi
).
toString
();
String
aa3
=
Generator
.
createDaoImpl
(
"E:\\
A-ZM-work\\work_qxb2\\qxbplatform\\qixingbao-show
\\src\\main\\java\\"
,
bi
).
toString
();
String
aa4
=
Generator
.
createService
(
"E:\\
A-ZM-work\\work_qxb2\\qxbplatform\\qixingbao-show
\\src\\main\\java\\"
,
bi
).
toString
();
String
aa5
=
Generator
.
createServiceImpl
(
"E:\\
A-ZM-work\\work_qxb2\\qxbplatform\\qixingbao-show
\\src\\main\\java\\"
,
bi
).
toString
();
String
aa6
=
Generator
.
createController
(
"E:\\
A-ZM-work\\work_qxb2\\qxbplatform\\qixingbao-show\\src\\main\\java\\"
,
bi
).
toString
();
System
.
out
.
println
(
aa1
);
/*
System.out.println(aa2);
System
.
out
.
println
(
aa2
);
System
.
out
.
println
(
aa3
);
System
.
out
.
println
(
aa4
);
System
.
out
.
println
(
aa5
);
System.out.println(aa6);
*/
System
.
out
.
println
(
aa6
);
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
...
...
src/main/java/com/github/mybatis/util/EntityInfoUtil.java
View file @
0e69ee74
...
...
@@ -29,19 +29,27 @@ public class EntityInfoUtil {
String
comment
=
executeQuery
.
getString
(
3
);
PropertyInfo
ci
=
new
PropertyInfo
();
ci
.
setColumn
(
column
);
if
(
jdbcType
.
equals
(
"int"
))
{
if
(
jdbcType
.
equals
IgnoreCase
(
"int"
))
{
ci
.
setJdbcType
(
"Integer"
);
}
else
if
(
jdbcType
.
equalsIgnoreCase
(
"datetime"
))
{
ci
.
setJdbcType
(
"timestamp"
);
}
else
{
ci
.
setJdbcType
(
jdbcType
);
}
ci
.
setComment
(
comment
);
ci
.
setProperty
(
MySqlToJavaUtil
.
changeToJavaFiled
(
column
));
ci
.
setJavaType
(
MySqlToJavaUtil
.
jdbcTypeToJavaType
(
jdbcType
));
//设置注解类型
if
(
column
.
equalsIgnoreCase
(
"id"
))
{
bi
.
setIdType
(
ci
.
getJavaType
());
bi
.
setIdJdbcType
(
ci
.
getJdbcType
());
}
columns
.
add
(
ci
);
}
bi
.
setCis
(
columns
);
return
bi
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
RuntimeException
(
"自动生成实体类错误:"
+
e
.
getMessage
());
}
finally
{
pstemt
.
close
();
...
...
src/main/resources/freemarker/ftl/controller.ftl
View file @
0e69ee74
...
...
@@ -55,8 +55,8 @@ public class ${entityName}Controller {
*/
@
GetMapping
(
"/get${entityName}ById/{id}"
)
@
ApiOperation
(
value
=
"获取${entityComment}信息"
,
notes
=
"获取${entityComment}信息[${objectName}],作者:${author}"
)
@
ApiImplicitParam
(
paramType
=
"path"
,
name
=
"id"
,
value
=
"${entityComment}id"
,
required
=
true
,
dataType
=
"
Long
"
)
public
JsonResult
<${
entityName
}>
get
${
entityName
}
ById
(@
PathVariable
(
"id"
)
Long
id
){
@
ApiImplicitParam
(
paramType
=
"path"
,
name
=
"id"
,
value
=
"${entityComment}id"
,
required
=
true
,
dataType
=
"
${idType}
"
)
public
JsonResult
<${
entityName
}>
get
${
entityName
}
ById
(@
PathVariable
(
"id"
)
${
idType
}
id
){
JsonResult
<${
entityName
}>
result
=
new
JsonResult
<${
entityName
}>();
try
{
${
entityName
}
${
objectName
}=${
objectName
}
ServiceImpl
.
selectByPrimaryKey
(
id
);
...
...
@@ -116,9 +116,9 @@ public class ${entityName}Controller {
*/
@
PostMapping
(
"/deleteByPrimaryKey"
)
@
ApiOperation
(
value
=
"删除${entityComment}"
,
notes
=
"删除${entityComment},作者:${author}"
)
@
ApiImplicitParam
(
paramType
=
"query"
,
name
=
"id"
,
value
=
"${entityComment}id"
,
required
=
true
,
dataType
=
"
Long
"
)
public
JsonResult
deleteByPrimaryKey
(
Long
id
){
JsonResult
result
=
new
JsonResult
();
@
ApiImplicitParam
(
paramType
=
"query"
,
name
=
"id"
,
value
=
"${entityComment}id"
,
required
=
true
,
dataType
=
"
${idType}
"
)
public
JsonResult
<
Object
>
deleteByPrimaryKey
(${
idType
}
id
){
JsonResult
<
Object
>
result
=
new
JsonResult
<
Object
>
();
try
{
int
reg
=${
objectName
}
ServiceImpl
.
deleteByPrimaryKey
(
id
);
if
(
reg
>
0
)
{
...
...
@@ -177,8 +177,8 @@ public class ${entityName}Controller {
*/
@
ApiOperation
(
value
=
"条件查询${entityComment}"
,
notes
=
"条件查询[${objectName}],作者:${author}"
)
@
PostMapping
(
"/query${entityName}List"
)
public
JsonResult
<
${
entityName
}
>
query
${
entityName
}
List
(${
entityName
}
${
objectName
}){
JsonResult
<
${
entityName
}>
result
=
new
JsonResult
<${
entityName
}
>();
public
JsonResult
<
List
<${
entityName
}>
>
query
${
entityName
}
List
(${
entityName
}
${
objectName
}){
JsonResult
<
List
<${
entityName
}>>
result
=
new
JsonResult
<
List
<${
entityName
}>
>();
try
{
List
<${
entityName
}>
list
=
${
objectName
}
ServiceImpl
.
query
${
entityName
}
List
(${
objectName
});
result
.
setCode
(
1
);
...
...
@@ -205,8 +205,8 @@ public class ${entityName}Controller {
@
ApiImplicitParam
(
paramType
=
"query"
,
name
=
"pageNum"
,
value
=
"当前页"
,
required
=
true
,
dataType
=
"int"
),
@
ApiImplicitParam
(
paramType
=
"query"
,
name
=
"pageSize"
,
value
=
"页行数"
,
required
=
true
,
dataType
=
"int"
)
})
public
JsonResult
<
${
entityName
}
>
get
${
entityName
}
BySearch
(
Integer
pageNum
,
Integer
pageSize
){
JsonResult
<
${
entityName
}>
result
=
new
JsonResult
<${
entityName
}
>();
public
JsonResult
<
PageInfo
<${
entityName
}>
>
get
${
entityName
}
BySearch
(
Integer
pageNum
,
Integer
pageSize
){
JsonResult
<
PageInfo
<${
entityName
}>>
result
=
new
JsonResult
<
PageInfo
<${
entityName
}>
>();
AppPage
<${
entityName
}>
page
=
new
AppPage
<${
entityName
}>();
page
.
setPageNum
(
pageNum
);
page
.
setPageSize
(
pageSize
);
...
...
src/main/resources/freemarker/ftl/dao.ftl
View file @
0e69ee74
...
...
@@ -21,9 +21,9 @@ import ${entityUrl}.${entityName};
@
Mapper
public
interface
${
entityName
}
Dao
{
public
${
entityName
}
selectByPrimaryKey
(
Long
id
);
public
${
entityName
}
selectByPrimaryKey
(
${
idType
}
id
);
public
int
deleteByPrimaryKey
(
Long
id
);
public
int
deleteByPrimaryKey
(
${
idType
}
id
);
public
int
insertSelective
(${
entityName
}
${
objectName
});
...
...
src/main/resources/freemarker/ftl/mapper.ftl
View file @
0e69ee74
...
...
@@ -10,21 +10,21 @@
${agile}
</sql>
<!-- 查询 -->
<select
id=
"selectByPrimaryKey"
parameterType=
"java.lang.
Long
"
<select
id=
"selectByPrimaryKey"
parameterType=
"java.lang.
${idType}
"
resultMap=
"BaseResultMap"
>
select
<include
refid=
"Base_Column_List"
/>
from ${table}
where id = ${r'#{
id,jdbcType=BIGINT}'
}
where id = ${r'#{
'}id,jdbcType=${idJdbcType?upper_case}
}
</select>
<!-- 删除 -->
<delete
id=
"deleteByPrimaryKey"
parameterType=
"java.lang.
Long
"
>
<delete
id=
"deleteByPrimaryKey"
parameterType=
"java.lang.
${idType}
"
>
delete from ${table}
where id = ${r'#{
id,jdbcType=BIGINT}'
}
where id = ${r'#{
'}id,jdbcType=${idJdbcType?upper_case}
}
</delete>
<!-- 选择添加 -->
<insert
id=
"insertSelective"
parameterType=
"${entityUrl}.${entityName}"
>
<selectKey
keyProperty=
"id"
order=
"AFTER"
resultType=
"java.lang.
Long
"
>
<selectKey
keyProperty=
"id"
order=
"AFTER"
resultType=
"java.lang.
${idType}
"
>
SELECT
LAST_INSERT_ID()
</selectKey>
...
...
@@ -54,7 +54,7 @@
</if>
<
/#list>
</set>
where id = ${r'#{
id,jdbcType=BIGINT}'
}
where id = ${r'#{
'}id,jdbcType=${idJdbcType}
}
</update>
<!-- 组合条件查询 -->
<select
id=
"query${entityName}List"
parameterType=
"${entityUrl}.${entityName}"
...
...
@@ -64,7 +64,7 @@
from ${table}
<where>
<if
test=
"id != null"
>
id = ${r'#{'}id,jdbcType=
BIGINT
}
id = ${r'#{'}id,jdbcType=
${idJdbcType?upper_case}
}
</if>
<
#list cis as ci>
<
#if ci.column!="id">
...
...
src/main/resources/freemarker/ftl/service.ftl
View file @
0e69ee74
...
...
@@ -27,7 +27,7 @@ public interface ${entityName}Service {
*
@
return
${
entityName
}
*
@
author
${
author
}
*/
public
${
entityName
}
selectByPrimaryKey
(
Long
id
);
public
${
entityName
}
selectByPrimaryKey
(
${
idType
}
id
);
/**
*
@
explain
删除
${
entityComment
}
对象
...
...
@@ -35,7 +35,7 @@ public interface ${entityName}Service {
*
@
return
int
*
@
author
${
author
}
*/
public
int
deleteByPrimaryKey
(
Long
id
);
public
int
deleteByPrimaryKey
(
${
idType
}
id
);
/**
*
@
explain
添加
${
entityComment
}
对象
...
...
src/main/resources/freemarker/ftl/serviceImpl.ftl
View file @
0e69ee74
...
...
@@ -34,13 +34,13 @@ public class ${entityName}ServiceImpl implements ${entityName}Service {
//
查询对象
@
Override
public
${
entityName
}
selectByPrimaryKey
(
Long
id
)
{
public
${
entityName
}
selectByPrimaryKey
(
${
idType
}
id
)
{
return
${
objectName
}
Dao
.
selectByPrimaryKey
(
id
);
}
//
删除对象
@
Override
public
int
deleteByPrimaryKey
(
Long
id
)
{
public
int
deleteByPrimaryKey
(
${
idType
}
id
)
{
return
${
objectName
}
Dao
.
deleteByPrimaryKey
(
id
);
}
...
...
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