Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Eladmin
Commits
203c1d69
Commit
203c1d69
authored
Nov 25, 2019
by
dqjdda
Browse files
代码生成器优化,生成代码更加便捷
parent
e4ca7afc
Changes
22
Hide whitespace changes
Inline
Side-by-side
eladmin-generator/src/main/java/me/zhengjie/domain/GenConfig.java
View file @
203c1d69
...
...
@@ -30,6 +30,9 @@ public class GenConfig {
@NotBlank
private
String
tableName
;
/** 接口名称 **/
private
String
apiAlias
;
/** 包路径 */
@NotBlank
private
String
pack
;
...
...
eladmin-generator/src/main/java/me/zhengjie/utils/GenUtil.java
View file @
203c1d69
...
...
@@ -58,13 +58,14 @@ public class GenUtil {
List
<
String
>
templateNames
=
new
ArrayList
<>();
templateNames
.
add
(
"api"
);
templateNames
.
add
(
"index"
);
templateNames
.
add
(
"eForm"
);
return
templateNames
;
}
public
static
void
generatorCode
(
List
<
ColumnInfo
>
columnInfos
,
GenConfig
genConfig
)
throws
IOException
{
// 存储模版字段数据
Map
<
String
,
Object
>
genMap
=
new
HashMap
<>(
16
);
// 接口别名
genMap
.
put
(
"apiAlias"
,
genConfig
.
getApiAlias
());
// 包名称
genMap
.
put
(
"package"
,
genConfig
.
getPack
());
// 模块名称
...
...
@@ -110,8 +111,8 @@ public class GenUtil {
List
<
Map
<
String
,
Object
>>
queryColumns
=
new
ArrayList
<>();
// 存储字典信息
List
<
String
>
dicts
=
new
ArrayList
<>();
// 存储
DateRange
信息
List
<
Map
<
String
,
Object
>>
dateRange
s
=
new
ArrayList
<>();
// 存储
between
信息
List
<
Map
<
String
,
Object
>>
between
s
=
new
ArrayList
<>();
// 存储不为空的字段信息
List
<
Map
<
String
,
Object
>>
isNotNullColumns
=
new
ArrayList
<>();
...
...
@@ -194,8 +195,8 @@ public class GenUtil {
// 查询中存储 BigDecimal 类型
genMap
.
put
(
"queryHasBigDecimal"
,
true
);
}
if
(
"
DateRange
"
.
equalsIgnoreCase
(
column
.
getQueryType
())){
dateRange
s
.
add
(
listMap
);
if
(
"
between
"
.
equalsIgnoreCase
(
column
.
getQueryType
())){
between
s
.
add
(
listMap
);
}
else
{
// 添加到查询列表中
queryColumns
.
add
(
listMap
);
...
...
@@ -211,7 +212,7 @@ public class GenUtil {
// 保存字段列表
genMap
.
put
(
"dicts"
,
dicts
);
// 保存查询列表
genMap
.
put
(
"
dateRanges"
,
dateRange
s
);
genMap
.
put
(
"
betweens"
,
between
s
);
// 保存非空字段信息
genMap
.
put
(
"isNotNullColumns"
,
isNotNullColumns
);
TemplateEngine
engine
=
TemplateUtil
.
createEngine
(
new
TemplateConfig
(
"template"
,
TemplateConfig
.
ResourceMode
.
CLASSPATH
));
...
...
@@ -277,7 +278,7 @@ public class GenUtil {
}
if
(
"Dto"
.
equals
(
templateName
))
{
return
packagePath
+
"service"
+
File
.
separator
+
"dto"
+
File
.
separator
+
className
+
"D
TO
.java"
;
return
packagePath
+
"service"
+
File
.
separator
+
"dto"
+
File
.
separator
+
className
+
"D
to
.java"
;
}
if
(
"QueryCriteria"
.
equals
(
templateName
))
{
...
...
@@ -309,9 +310,6 @@ public class GenUtil {
return
path
+
File
.
separator
+
"index.vue"
;
}
if
(
"eForm"
.
equals
(
templateName
))
{
return
path
+
File
.
separator
+
File
.
separator
+
"form.vue"
;
}
return
null
;
}
...
...
eladmin-system/src/main/java/me/zhengjie/gen/domain/GenTest.java
0 → 100644
View file @
203c1d69
package
me.zhengjie.gen.domain
;
import
lombok.Data
;
import
cn.hutool.core.bean.BeanUtil
;
import
cn.hutool.core.bean.copier.CopyOptions
;
import
javax.persistence.*
;
import
javax.validation.constraints.*
;
import
javax.persistence.Entity
;
import
javax.persistence.Table
;
import
org.hibernate.annotations.*
;
import
java.sql.Timestamp
;
import
java.io.Serializable
;
/**
* @author Zheng Jie
* @date 2019-11-25
*/
@Entity
@Data
@Table
(
name
=
"gen_test"
)
public
class
GenTest
implements
Serializable
{
/** ID */
@Id
@Column
(
name
=
"id"
)
private
Long
id
;
/** 名称 */
@Column
(
name
=
"name"
,
nullable
=
false
)
@NotBlank
private
String
name
;
/** 状态 */
@Column
(
name
=
"status"
,
nullable
=
false
)
@NotNull
private
Boolean
status
;
/** 日期 */
@Column
(
name
=
"date"
,
nullable
=
false
)
@NotNull
private
Timestamp
date
;
/** 创建日期 */
@Column
(
name
=
"create_time"
)
@CreationTimestamp
private
Timestamp
createTime
;
public
void
copy
(
GenTest
source
){
BeanUtil
.
copyProperties
(
source
,
this
,
CopyOptions
.
create
().
setIgnoreNullValue
(
true
));
}
}
\ No newline at end of file
eladmin-system/src/main/java/me/zhengjie/gen/repository/GenTestRepository.java
0 → 100644
View file @
203c1d69
package
me.zhengjie.gen.repository
;
import
me.zhengjie.gen.domain.GenTest
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.JpaSpecificationExecutor
;
/**
* @author Zheng Jie
* @date 2019-11-25
*/
public
interface
GenTestRepository
extends
JpaRepository
<
GenTest
,
Long
>,
JpaSpecificationExecutor
<
GenTest
>
{
}
\ No newline at end of file
eladmin-system/src/main/java/me/zhengjie/gen/rest/GenTestController.java
0 → 100644
View file @
203c1d69
package
me.zhengjie.gen.rest
;
import
me.zhengjie.aop.log.Log
;
import
me.zhengjie.gen.domain.GenTest
;
import
me.zhengjie.gen.service.GenTestService
;
import
me.zhengjie.gen.service.dto.GenTestQueryCriteria
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
io.swagger.annotations.*
;
import
java.io.IOException
;
import
javax.servlet.http.HttpServletResponse
;
/**
* @author Zheng Jie
* @date 2019-11-25
*/
@Api
(
tags
=
"测试生成管理"
)
@RestController
@RequestMapping
(
"/api/genTest"
)
public
class
GenTestController
{
private
final
GenTestService
genTestService
;
public
GenTestController
(
GenTestService
genTestService
)
{
this
.
genTestService
=
genTestService
;
}
@Log
(
"导出数据"
)
@ApiOperation
(
"导出数据"
)
@GetMapping
(
value
=
"/download"
)
@PreAuthorize
(
"@el.check('genTest:list')"
)
public
void
download
(
HttpServletResponse
response
,
GenTestQueryCriteria
criteria
)
throws
IOException
{
genTestService
.
download
(
genTestService
.
queryAll
(
criteria
),
response
);
}
@GetMapping
@Log
(
"查询测试生成"
)
@ApiOperation
(
"查询测试生成"
)
@PreAuthorize
(
"@el.check('genTest:list')"
)
public
ResponseEntity
getGenTests
(
GenTestQueryCriteria
criteria
,
Pageable
pageable
){
return
new
ResponseEntity
<>(
genTestService
.
queryAll
(
criteria
,
pageable
),
HttpStatus
.
OK
);
}
@PostMapping
@Log
(
"新增测试生成"
)
@ApiOperation
(
"新增测试生成"
)
@PreAuthorize
(
"@el.check('genTest:add')"
)
public
ResponseEntity
create
(
@Validated
@RequestBody
GenTest
resources
){
return
new
ResponseEntity
<>(
genTestService
.
create
(
resources
),
HttpStatus
.
CREATED
);
}
@PutMapping
@Log
(
"修改测试生成"
)
@ApiOperation
(
"修改测试生成"
)
@PreAuthorize
(
"@el.check('genTest:edit')"
)
public
ResponseEntity
update
(
@Validated
@RequestBody
GenTest
resources
){
genTestService
.
update
(
resources
);
return
new
ResponseEntity
(
HttpStatus
.
NO_CONTENT
);
}
@DeleteMapping
(
value
=
"/{id}"
)
@Log
(
"删除测试生成"
)
@ApiOperation
(
"删除测试生成"
)
@PreAuthorize
(
"@el.check('genTest:del')"
)
public
ResponseEntity
delete
(
@PathVariable
Long
id
){
genTestService
.
delete
(
id
);
return
new
ResponseEntity
(
HttpStatus
.
OK
);
}
@Log
(
"多选删除测试生成"
)
@ApiOperation
(
"多选删除测试生成"
)
@PreAuthorize
(
"@el.check('genTest:del')"
)
@DeleteMapping
public
ResponseEntity
deleteAll
(
@RequestBody
Long
[]
ids
)
{
genTestService
.
deleteAll
(
ids
);
return
new
ResponseEntity
(
HttpStatus
.
OK
);
}
}
\ No newline at end of file
eladmin-system/src/main/java/me/zhengjie/gen/service/GenTestService.java
0 → 100644
View file @
203c1d69
package
me.zhengjie.gen.service
;
import
me.zhengjie.gen.domain.GenTest
;
import
me.zhengjie.gen.service.dto.GenTestDto
;
import
me.zhengjie.gen.service.dto.GenTestQueryCriteria
;
import
org.springframework.data.domain.Pageable
;
import
java.util.Map
;
import
java.util.List
;
import
java.io.IOException
;
import
javax.servlet.http.HttpServletResponse
;
/**
* @author Zheng Jie
* @date 2019-11-25
*/
public
interface
GenTestService
{
/**
* 查询数据分页
* @param criteria 条件
* @param pageable 分页参数
* @return Map<String,Object>
*/
Map
<
String
,
Object
>
queryAll
(
GenTestQueryCriteria
criteria
,
Pageable
pageable
);
/**
* 查询所有数据不分页
* @param criteria 条件参数
* @return List<GenTestDto>
*/
List
<
GenTestDto
>
queryAll
(
GenTestQueryCriteria
criteria
);
/**
* 根据ID查询
* @param id ID
* @return GenTestDto
*/
GenTestDto
findById
(
Long
id
);
/**
* 创建
* @param resources /
* @return GenTestDto
*/
GenTestDto
create
(
GenTest
resources
);
/**
* 编辑
* @param resources /
*/
void
update
(
GenTest
resources
);
/**
* 删除
* @param id /
*/
void
delete
(
Long
id
);
/**
* 多选删除
* @param ids /
*/
void
deleteAll
(
Long
[]
ids
);
/**
* 导出数据
* @param all 待导出的数据
* @param response /
* @throws IOException /
*/
void
download
(
List
<
GenTestDto
>
all
,
HttpServletResponse
response
)
throws
IOException
;
}
\ No newline at end of file
eladmin-system/src/main/java/me/zhengjie/gen/service/dto/GenTestDto.java
0 → 100644
View file @
203c1d69
package
me.zhengjie.gen.service.dto
;
import
lombok.Data
;
import
java.sql.Timestamp
;
import
java.io.Serializable
;
import
com.fasterxml.jackson.databind.annotation.JsonSerialize
;
import
com.fasterxml.jackson.databind.ser.std.ToStringSerializer
;
/**
* @author Zheng Jie
* @date 2019-11-25
*/
@Data
public
class
GenTestDto
implements
Serializable
{
/** ID */
/** 防止精度丢失 */
@JsonSerialize
(
using
=
ToStringSerializer
.
class
)
private
Long
id
;
/** 名称 */
private
String
name
;
/** 状态 */
private
Boolean
status
;
/** 日期 */
private
Timestamp
date
;
/** 创建日期 */
private
Timestamp
createTime
;
}
\ No newline at end of file
eladmin-system/src/main/java/me/zhengjie/gen/service/dto/GenTestQueryCriteria.java
0 → 100644
View file @
203c1d69
package
me.zhengjie.gen.service.dto
;
import
lombok.Data
;
import
java.sql.Timestamp
;
import
java.util.List
;
import
me.zhengjie.annotation.Query
;
/**
* @author Zheng Jie
* @date 2019-11-25
*/
@Data
public
class
GenTestQueryCriteria
{
/** 模糊 */
@Query
(
type
=
Query
.
Type
.
INNER_LIKE
)
private
String
name
;
/** 精确 */
@Query
private
Boolean
status
;
/** BETWEEN */
@Query
(
type
=
Query
.
Type
.
BETWEEN
)
private
List
<
Timestamp
>
createTime
;
}
\ No newline at end of file
eladmin-system/src/main/java/me/zhengjie/gen/service/impl/GenTestServiceImpl.java
0 → 100644
View file @
203c1d69
package
me.zhengjie.gen.service.impl
;
import
me.zhengjie.gen.domain.GenTest
;
import
me.zhengjie.utils.ValidationUtil
;
import
me.zhengjie.utils.FileUtil
;
import
me.zhengjie.gen.repository.GenTestRepository
;
import
me.zhengjie.gen.service.GenTestService
;
import
me.zhengjie.gen.service.dto.GenTestDto
;
import
me.zhengjie.gen.service.dto.GenTestQueryCriteria
;
import
me.zhengjie.gen.service.mapper.GenTestMapper
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
cn.hutool.core.lang.Snowflake
;
import
cn.hutool.core.util.IdUtil
;
import
org.springframework.cache.annotation.CacheConfig
;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Pageable
;
import
me.zhengjie.utils.PageUtil
;
import
me.zhengjie.utils.QueryHelp
;
import
java.util.List
;
import
java.util.Map
;
import
java.io.IOException
;
import
javax.servlet.http.HttpServletResponse
;
import
java.util.ArrayList
;
import
java.util.LinkedHashMap
;
/**
* @author Zheng Jie
* @date 2019-11-25
*/
@Service
@CacheConfig
(
cacheNames
=
"genTest"
)
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
public
class
GenTestServiceImpl
implements
GenTestService
{
private
final
GenTestRepository
genTestRepository
;
private
final
GenTestMapper
genTestMapper
;
public
GenTestServiceImpl
(
GenTestRepository
genTestRepository
,
GenTestMapper
genTestMapper
)
{
this
.
genTestRepository
=
genTestRepository
;
this
.
genTestMapper
=
genTestMapper
;
}
@Override
@Cacheable
public
Map
<
String
,
Object
>
queryAll
(
GenTestQueryCriteria
criteria
,
Pageable
pageable
){
Page
<
GenTest
>
page
=
genTestRepository
.
findAll
((
root
,
criteriaQuery
,
criteriaBuilder
)
->
QueryHelp
.
getPredicate
(
root
,
criteria
,
criteriaBuilder
),
pageable
);
return
PageUtil
.
toPage
(
page
.
map
(
genTestMapper:
:
toDto
));
}
@Override
@Cacheable
public
List
<
GenTestDto
>
queryAll
(
GenTestQueryCriteria
criteria
){
return
genTestMapper
.
toDto
(
genTestRepository
.
findAll
((
root
,
criteriaQuery
,
criteriaBuilder
)
->
QueryHelp
.
getPredicate
(
root
,
criteria
,
criteriaBuilder
)));
}
@Override
@Cacheable
(
key
=
"#p0"
)
public
GenTestDto
findById
(
Long
id
)
{
GenTest
genTest
=
genTestRepository
.
findById
(
id
).
orElseGet
(
GenTest:
:
new
);
ValidationUtil
.
isNull
(
genTest
.
getId
(),
"GenTest"
,
"id"
,
id
);
return
genTestMapper
.
toDto
(
genTest
);
}
@Override
@CacheEvict
(
allEntries
=
true
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
GenTestDto
create
(
GenTest
resources
)
{
Snowflake
snowflake
=
IdUtil
.
createSnowflake
(
1
,
1
);
resources
.
setId
(
snowflake
.
nextId
());
return
genTestMapper
.
toDto
(
genTestRepository
.
save
(
resources
));
}
@Override
@CacheEvict
(
allEntries
=
true
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
update
(
GenTest
resources
)
{
GenTest
genTest
=
genTestRepository
.
findById
(
resources
.
getId
()).
orElseGet
(
GenTest:
:
new
);
ValidationUtil
.
isNull
(
genTest
.
getId
(),
"GenTest"
,
"id"
,
resources
.
getId
());
genTest
.
copy
(
resources
);
genTestRepository
.
save
(
genTest
);
}
@Override
@CacheEvict
(
allEntries
=
true
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
delete
(
Long
id
)
{
genTestRepository
.
deleteById
(
id
);
}
@Override
@CacheEvict
(
allEntries
=
true
)
public
void
deleteAll
(
Long
[]
ids
)
{
for
(
Long
id
:
ids
)
{
genTestRepository
.
deleteById
(
id
);
}
}
@Override
public
void
download
(
List
<
GenTestDto
>
all
,
HttpServletResponse
response
)
throws
IOException
{
List
<
Map
<
String
,
Object
>>
list
=
new
ArrayList
<>();
for
(
GenTestDto
genTest
:
all
)
{
Map
<
String
,
Object
>
map
=
new
LinkedHashMap
<>();
map
.
put
(
"名称"
,
genTest
.
getName
());
map
.
put
(
"状态"
,
genTest
.
getStatus
());
map
.
put
(
"日期"
,
genTest
.
getDate
());
map
.
put
(
"创建日期"
,
genTest
.
getCreateTime
());
list
.
add
(
map
);
}
FileUtil
.
downloadExcel
(
list
,
response
);
}
}
\ No newline at end of file
eladmin-system/src/main/java/me/zhengjie/gen/service/mapper/GenTestMapper.java
0 → 100644
View file @
203c1d69
package
me.zhengjie.gen.service.mapper
;
import
me.zhengjie.base.BaseMapper
;
import
me.zhengjie.gen.domain.GenTest
;
import
me.zhengjie.gen.service.dto.GenTestDto
;
import
org.mapstruct.Mapper
;
import
org.mapstruct.ReportingPolicy
;
/**
* @author Zheng Jie
* @date 2019-11-25
*/
@Mapper
(
componentModel
=
"spring"
,
unmappedTargetPolicy
=
ReportingPolicy
.
IGNORE
)
public
interface
GenTestMapper
extends
BaseMapper
<
GenTestDto
,
GenTest
>
{
}
\ No newline at end of file
eladmin-system/src/main/java/me/zhengjie/modules/system/repository/DeptRepository.java
View file @
203c1d69
...
...
@@ -17,7 +17,7 @@ public interface DeptRepository extends JpaRepository<Dept, Long>, JpaSpecificat
/**
* 根据 PID 查询
* @param id pid
* @return
、
* @return
/
*/
List
<
Dept
>
findByPid
(
Long
id
);
...
...
eladmin-system/src/main/resources/template/generator/admin/Controller.ftl
View file @
203c1d69
...
...
@@ -18,7 +18,7 @@ import javax.servlet.http.HttpServletResponse;
*
@author $
{
author
}
*
@date $
{
date
}
*/
@
Api
(
tags
=
"$
{
className
}
管理")
@
Api
(
tags
=
"$
{
apiAlias
}
管理")
@
RestController
@
RequestMapping
("/
api
/${
changeClassName
}")
public
class $
{
className
}
Controller
{
...
...
@@ -38,24 +38,24 @@ public class ${className}Controller {
}
@
G
etMapping
@
L
og
(
"查询${
className
}"
)
@
A
piOperation
(
"查询${
className
}"
)
@
L
og
(
"查询${
apiAlias
}"
)
@
A
piOperation
(
"查询${
apiAlias
}"
)
@
P
reAuthorize
(
"@el.check('${changeClassName}:list')"
)
public
R
esponseEntity
get
$
{
className
}
s
(
$
{
className
}
Q
ueryCriteria
criteria
,
P
ageable
pageable
){
return
new
R
esponseEntity
<>
(
$
{
changeClassName
}
S
ervice
.queryAll
(
criteria
,
pageable
),
H
ttpStatus
.OK
)
;
}
@
P
ostMapping
@
L
og
(
"新增${
className
}"
)
@
A
piOperation
(
"新增${
className
}"
)
@
L
og
(
"新增${
apiAlias
}"
)
@
A
piOperation
(
"新增${
apiAlias
}"
)
@
P
reAuthorize
(
"@el.check('${changeClassName}:add')"
)
public
R
esponseEntity
create
(
@
V
alidated
@
R
equestBody
$
{
className
}
resources
){
return
new
R
esponseEntity
<>
(
$
{
changeClassName
}
S
ervice
.create
(
resources
),
H
ttpStatus
.CREATED
)
;
}
@
P
utMapping
@
L
og
(
"修改${
className
}"
)
@
A
piOperation
(
"修改${
className
}"
)
@
L
og
(
"修改${
apiAlias
}"
)
@
A
piOperation
(
"修改${
apiAlias
}"
)
@
P
reAuthorize
(
"@el.check('${changeClassName}:edit')"
)
public
R
esponseEntity
update
(
@
V
alidated
@
R
equestBody
$
{
className
}
resources
){
$
{
changeClassName
}
S
ervice
.update
(
resources
)
;
...
...
@@ -63,16 +63,16 @@ public class ${className}Controller {
}
@
D
eleteMapping
(
value
=
"/{${pkChangeColName}}"
)
@
L
og
(
"删除${
className
}"
)
@
A
piOperation
(
"删除${
className
}"
)
@
L
og
(
"删除${
apiAlias
}"
)
@
A
piOperation
(
"删除${
apiAlias
}"
)
@
P
reAuthorize
(
"@el.check('${changeClassName}:del')"
)
public
R
esponseEntity
delete
(
@
P
athVariable
$
{
pkColumnType
}
$
{
pkChangeColName
}){
$
{
changeClassName
}
S
ervice
.delete
(
$
{
pkChangeColName
})
;
return
new
R
esponseEntity
(
H
ttpStatus
.OK
)
;
}
@
L
og
(
"多选删除${
className
}"
)
@
A
piOperation
(
"多选删除${
className
}"
)
@
L
og
(
"多选删除${
apiAlias
}"
)
@
A
piOperation
(
"多选删除${
apiAlias
}"
)
@
P
reAuthorize
(
"@el.check('${changeClassName}:del')"
)
@
D
eleteMapping
public
R
esponseEntity
deleteAll
(
@
R
equestBody
$
{
pkColumnType
}
[]
ids
)
{
...
...
eladmin-system/src/main/resources/template/generator/admin/Dto.ftl
View file @
203c1d69
...
...
@@ -13,22 +13,21 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import
com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
</#
if
>
/**
*
@author $
{
author
}
*
@date $
{
date
}
*/
@
Data
public
class $
{
className
}
D
TO
implements Serializable
{
public
class $
{
className
}
D
to
implements Serializable
{
<#
if
columns
??>
<#
list
columns
as
column
>
<#
if
column
.remark
!=
''>
/
/
$
{
column
.remark
}
/
**
$
{
column
.remark
}
*
/
</#
if
>
<#
if
column
.columnKey
=
'
PRI
'>
<#
if
!
auto
&&
pkColumnType
=
'
L
ong
'>
/
/
处理
精度丢失
问题
/
**
防止
精度丢失
*
/
@
J
sonSerialize
(
using
=
T
oStringSerializer
.class
)
</#
if
>
</#
if
>
...
...
eladmin-system/src/main/resources/template/generator/admin/Entity.ftl
View file @
203c1d69
...
...
@@ -32,7 +32,7 @@ public class ${className} implements Serializable {
<#
list
columns
as
column
>
<#
if
column
.remark
!=
''>
/
/
$
{
column
.remark
}
/
**
$
{
column
.remark
}
*
/
</#
if
>
<#
if
column
.columnKey
=
'
PRI
'>
@
I
d
...
...
eladmin-system/src/main/resources/template/generator/admin/Mapper.ftl
View file @
203c1d69
...
...
@@ -2,7 +2,7 @@ package ${package}.service.mapper;
import
me.zhengjie.base.BaseMapper;
import
$
{
package
}
.domain.$
{
className
}
;
import
$
{
package
}
.service.dto.$
{
className
}
D
TO
;
import
$
{
package
}
.service.dto.$
{
className
}
D
to
;
import
org.mapstruct.Mapper;
import
org.mapstruct.ReportingPolicy;
...
...
@@ -11,6 +11,6 @@ import org.mapstruct.ReportingPolicy;
*
@date $
{
date
}
*/
@
Mapper
(
componentModel
=
"spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public
interface $
{
className
}
Mapper extends BaseMapper<$
{
className
}
D
TO
, $
{
className
}
>
{
public
interface $
{
className
}
Mapper extends BaseMapper<$
{
className
}
D
to
, $
{
className
}
>
{
}
\ No newline at end of file
eladmin-system/src/main/resources/template/generator/admin/QueryCriteria.ftl
View file @
203c1d69
...
...
@@ -7,7 +7,7 @@ import java.sql.Timestamp;
<#
if
queryHasBigDecimal>
import
java.math.BigDecimal;
</#
if
>
<#
if
dateRange
s??>
<#
if
between
s??>
import
java.util.List;
</#
if
>
<#
if
queryColumns??>
...
...
@@ -24,34 +24,35 @@ public class ${className}QueryCriteria{
<#
list
queryColumns
as
column
>
<#
if
column
.queryType
=
'='>
/
/
精确
/
**
精确
*
/
@
Q
uery
private
$
{
column
.columnType
}
$
{
column
.changeColumnName
}
;
</#
if
>
<#
if
column
.queryType
=
'
L
ike
'>
/
/
模糊
/
**
模糊
*
/
@
Q
uery
(
type
=
Q
uery
.Type.INNER_LIKE
)
private
$
{
column
.columnType
}
$
{
column
.changeColumnName
}
;
</#
if
>
<#
if
column
.queryType
=
'!='>
/
/
不等于
/
**
不等于
*
/
@
Q
uery
(
type
=
Q
uery
.Type.NOT_EQUAL
)
private
$
{
column
.columnType
}
$
{
column
.changeColumnName
}
;
</#
if
>
<#
if
column
.queryType
=
'>='>
/
/
大于等于
/
**
大于等于
*
/
@
Q
uery
(
type
=
Q
uery
.Type.GREATER_THAN
)
private
$
{
column
.columnType
}
$
{
column
.changeColumnName
}
;
</#
if
>
<#
if
column
.queryType
=
'<='>
/
/
小于等于
/
**
小于等于
*
/
@
Q
uery
(
type
=
Q
uery
.Type.LESS_THAN
)
private
$
{
column
.columnType
}
$
{
column
.changeColumnName
}
;
</#
if
>
</#
list
>
</#
if
>
<#
if
dateRanges
??>
<#
list
dateRanges
as
column
>
<#
if
betweens
??>
<#
list
betweens
as
column
>
/
**
BETWEEN
*
/
@
Q
uery
(
type
=
Q
uery
.Type.BETWEEN
)
private
L
ist
<$
{
column
.columnType
}
>
createTime
;
</#
list
>
...
...
eladmin-system/src/main/resources/template/generator/admin/Repository.ftl
View file @
203c1d69
...
...
@@ -12,7 +12,11 @@ public interface ${className}Repository extends JpaRepository<${className}, ${pk
<#
if
columns
??>
<#
list
columns
as
column
>
<#
if
column
.columnKey
=
'
UNI
'>
/
**
*
根据
$
{
column
.capitalColumnName
}
查询
*
@
param
$
{
column
.columnName
}
/
*
@
return
/
*
/
$
{
className
}
findBy
$
{
column
.capitalColumnName
}(
$
{
column
.columnType
}
$
{
column
.columnName
})
;
</#
if
>
</#
list
>
...
...
eladmin-system/src/main/resources/template/generator/admin/Service.ftl
View file @
203c1d69
...
...
@@ -17,7 +17,7 @@ public interface ${className}Service {
/
**
*
查询数据分页
*
@
param
criteria
条件
参数
*
@
param
criteria
条件
*
@
param
pageable
分页参数
*
@
return
M
ap
<
S
tring
,
O
bject
>
*
/
...
...
@@ -37,13 +37,36 @@ public interface ${className}Service {
*
/
$
{
className
}
D
to
findById
(
$
{
pkColumnType
}
$
{
pkChangeColName
})
;
/
**
*
创建
*
@
param
resources
/
*
@
return
$
{
className
}
D
to
*
/
$
{
className
}
D
to
create
(
$
{
className
}
resources
)
;
/
**
*
编辑
*
@
param
resources
/
*
/
void
update
(
$
{
className
}
resources
)
;
/
**
*
删除
*
@
param
$
{
pkChangeColName
}
/
*
/
void
delete
(
$
{
pkColumnType
}
$
{
pkChangeColName
})
;
/
**
*
多选删除
*
@
param
ids
/
*
/
void
deleteAll
(
$
{
pkColumnType
}
[]
ids
)
;
/
**
*
导出数据
*
@
param
all
待导出的数据
*
@
param
response
/
*
@
throws
IOE
xception
/
*
/
void
download
(
L
ist
<$
{
className
}
D
to
>
all
,
H
ttpServletResponse
response
)
throws
IOE
xception
;
}
\ No newline at end of file
eladmin-system/src/main/resources/template/generator/admin/ServiceImpl.ftl
View file @
203c1d69
...
...
@@ -14,7 +14,7 @@ import me.zhengjie.utils.ValidationUtil;
import
me.zhengjie.utils.FileUtil;
import
$
{
package
}
.repository.$
{
className
}
Repository;
import
$
{
package
}
.service.$
{
className
}
Service;
import
$
{
package
}
.service.dto.$
{
className
}
D
TO
;
import
$
{
package
}
.service.dto.$
{
className
}
D
to
;
import
$
{
package
}
.service.dto.$
{
className
}
QueryCriteria;
import
$
{
package
}
.service.mapper.$
{
className
}
Mapper;
import
org.springframework.stereotype.Service;
...
...
@@ -68,13 +68,13 @@ public class ${className}ServiceImpl implements ${className}Service {
@
O
verride
@
C
acheable
public
L
ist
<$
{
className
}
D
TO
>
queryAll
(
$
{
className
}
Q
ueryCriteria
criteria
){
public
L
ist
<$
{
className
}
D
to
>
queryAll
(
$
{
className
}
Q
ueryCriteria
criteria
){
return
$
{
changeClassName
}
M
apper
.toDto
(
$
{
changeClassName
}
R
epository
.findAll
((
root
,
criteriaQuery
,
criteriaBuilder
)
->
Q
ueryHelp
.getPredicate
(
root
,
criteria
,
criteriaBuilder
)))
;
}
@
O
verride
@
C
acheable
(
key
=
"#p0"
)
public
$
{
className
}
D
TO
findById
(
$
{
pkColumnType
}
$
{
pkChangeColName
})
{
public
$
{
className
}
D
to
findById
(
$
{
pkColumnType
}
$
{
pkChangeColName
})
{
$
{
className
}
$
{
changeClassName
}
=
$
{
changeClassName
}
R
epository
.findById
(
$
{
pkChangeColName
})
.orElseGet
(
$
{
className
}::
new
)
;
V
alidationUtil
.isNull
(
$
{
changeClassName
}
.get
$
{
pkCapitalColName
}(),
"${className}"
,
"${pkChangeColName}"
,
$
{
pkChangeColName
})
;
return
$
{
changeClassName
}
M
apper
.toDto
(
$
{
changeClassName
})
;
...
...
@@ -83,7 +83,7 @@ public class ${className}ServiceImpl implements ${className}Service {
@
O
verride
@
C
acheEvict
(
allEntries
=
true
)
@
T
ransactional
(
rollbackFor
=
E
xception
.class
)
public
$
{
className
}
D
TO
create
(
$
{
className
}
resources
)
{
public
$
{
className
}
D
to
create
(
$
{
className
}
resources
)
{
<#
if
!
auto
&&
pkColumnType
=
'
L
ong
'>
S
nowflake
snowflake
=
I
dUtil
.createSnowflake
(
1
,
1
)
;
resources
.set
$
{
pkCapitalColName
}(
snowflake
.nextId
())
;
...
...
@@ -142,9 +142,9 @@ public class ${className}ServiceImpl implements ${className}Service {
}
@
O
verride
public
void
download
(
L
ist
<$
{
className
}
D
TO
>
all
,
H
ttpServletResponse
response
)
throws
IOE
xception
{
public
void
download
(
L
ist
<$
{
className
}
D
to
>
all
,
H
ttpServletResponse
response
)
throws
IOE
xception
{
L
ist
<
M
ap
<
S
tring
,
O
bject
>>
list
=
new
A
rrayList
<>
()
;
for
(
$
{
className
}
D
TO
$
{
changeClassName
}
:
all
)
{
for
(
$
{
className
}
D
to
$
{
changeClassName
}
:
all
)
{
M
ap
<
S
tring
,
O
bject
>
map
=
new
L
inkedHashMap
<>
()
;
<#
list
columns
as
column
>
<#
if
column
.columnKey
!=
'
PRI
'>
...
...
eladmin-system/src/main/resources/template/generator/front/api.ftl
View file @
203c1d69
...
...
@@ -30,11 +30,4 @@ export function edit(data) {
})
}
export
function download$
{
className
}
(params)
{
return
request
({
url
:
'
api
/$
{
changeClassName
}
/
download
'
,
method
:
'
get
'
,
params
,
responseType
:
'
blob
'
})
}
export
default
{
add
,
edit
,
del
,
delAll
}
Prev
1
2
Next
Write
Preview
Supports
Markdown
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