JDL增强
BegCode在JHipster的基础上,对JDL的注解进行了增强,主要体现在以下几个方面。
2. 对entity增加多个注解
实体上增加的注解,主要为解决各种配置和控制的内容。
2.1 @importData注解
主要用途是系统生成时就有数据需要导入,这时使用这个注解。本注解没有参数,是True/False型注解。
要求存在和实体数据库表名同名的.csv
文件。
2.2 @skipFakeData注解
忽略模拟数据的生成,默认情况下JHipster会生成模拟用的假数据,但质量不好,所以用这个来注解取消。
本注解没有参数,是True/False型注解。
2.3 @moduleName注解
给实体指定模块(Module)时使用的,暂时不起作用。设计之初用来生成maven多模块项目的。
示例:
md
@moduleName(system)
entity User {}
此注解必须要有参数。
2.3 @addCustomMethod注解
该注解用来给实体相关的文件植入代码的,主要用在内置功能模块上。使用-
分隔的关键词代表不同的文件。
md
repository: 后端Repository文件
service: 后端Service文件
rest: 后端RestResource文件
dto: 后端Dto文件
listComponent: 前端列表组件文件
clientService: 前端Api文件
editComponent: 前端编辑组件文件
此注解必须要有参数。
示例:
md
@addCustomMethod(repository-service-rest-clientService)
entity User {}
2.4 @importDataFile注解
通过文件导入数据的注解,支持多个文件导入,使用-
分隔。
与@importData功能基本相同,不同在于@importData只导入自己实体同名的。
示例:
md
@importDataFile(jhi_authority-rel_jhi_authority\_\_view_permissions)
entity User {}
2.5 @extendAbstractAuditingEntity注解
继承注解,主要用来解决每个实体都存在的创建时间、创建人、修改时间、修改人等。
此注解无参数。
示例:
md
@extendAbstractAuditingEntity
entity User {}
最终效果:
2.5.1 Java实体文件
java
/**
* A user.
*/
@TableName(value = "jhi_user")
@org.springframework.data.elasticsearch.annotations.Document(indexName = "user")
public class User extends AbstractAuditingEntity<Long, User> implements Serializable {
private static final long serialVersionUID = 1L;
@TableId(value = "id", type = IdType.AUTO)
private Long id;
@NotNull
@Pattern(regexp = Constants.LOGIN_REGEX)
@Size(min = 1, max = 50)
@TableField(value = "login")
private String login;
}
2.5.2 AbstractAuditingEntity.java文件
java
@JsonIgnoreProperties(value = { "createdBy", "createdDate", "lastModifiedBy", "lastModifiedDate" }, allowGetters = true)
public abstract class AbstractAuditingEntity<T, E> implements Serializable {
private static final long serialVersionUID = 1L;
public abstract T getId();
@TableField(value = "created_by", fill = FieldFill.INSERT)
private Long createdBy;
@TableField(value = "created_date", fill = FieldFill.INSERT)
private ZonedDateTime createdDate;
@TableField(value = "last_modified_by", fill = FieldFill.INSERT_UPDATE)
private Long lastModifiedBy;
@TableField(value = "last_modified_date", fill = FieldFill.INSERT_UPDATE)
private ZonedDateTime lastModifiedDate;
}
2.5.3 UserDTO.java文件
java
/**
* {@link com.begcode.online.domain.User}的DTO。
*/
@Schema(description = "用户")
@Data
@ToString
@EqualsAndHashCode(callSuper = true)
@SuppressWarnings("common-java:DuplicatedBlocks")
public class UserDTO extends AbstractAuditingEntity<Long, UserDTO> {
/**
* 用户ID
*/
@NotNull
@Schema(description = "用户ID", required = true)
private Long id;
}
2.5.4 UserCriteria.java文件(查询参数对象)
java
@ParameterObject
@SuppressWarnings("common-java:DuplicatedBlocks")
public class UserCriteria implements Serializable, Criteria {
@BindQuery(column = "self.id")
private LongFilter id;
@BindQuery(column = "self.login")
private StringFilter login;
@BindQuery(column = "self.email")
private StringFilter email;
@BindQuery(column = "self.created_by")
private LongFilter createdBy;
@BindQuery(column = "self.created_date")
private ZonedDateTimeFilter createdDate;
@BindQuery(column = "self.last_modified_by")
private LongFilter lastModifiedBy;
@BindQuery(column = "self.last_modified_date")
private ZonedDateTimeFilter lastModifiedDate;
}
2.5.5 数据库建表xml文件
xml
<changeSet id="20231208055301-1" author="begcode">
<createTable tableName="jhi_user" remarks="用户">
<column name="created_by" type="bigint" remarks="创建者Id">
<constraints nullable="true" />
</column>
<column name="created_date" type="${datetimeType}" remarks="创建时间">
<constraints nullable="true" />
</column>
<column name="last_modified_by" type="bigint" remarks="修改者Id">
<constraints nullable="true" />
</column>
<column name="last_modified_date" type="${datetimeType}" remarks="修改时间">
<constraints nullable="true" />
</column>
</createTable>
</changeSet>
2.5.6 前端列表配置文件
javascript
const columns = (): VxeGridPropTypes.Columns =>
{
return [
{
fixed: 'left',
type: 'checkbox',
width: 60,
},
{
title: '头像地址',
field: 'imageUrl',
minWidth: 160,
visible: true,
treeNode: false,
params: {type: 'STRING'},
cellRender: {name: 'AAvatar'},
},
{
title: '创建者Id',
field: 'createdBy',
minWidth: 80,
visible: true,
treeNode: false,
params: {type: 'LONG'},
editRender: {name: 'AInputNumber', enabled: false},
},
{
title: '创建时间',
field: 'createdDate',
minWidth: 140,
visible: true,
treeNode: false,
params: {type: 'ZONED_DATE_TIME'},
formatter: ({cellValue}) => (cellValue ? dayjs(cellValue).format('YYYY-MM-DD hh:mm:ss') : ''),
},
{
title: '修改者Id',
field: 'lastModifiedBy',
minWidth: 80,
visible: true,
treeNode: false,
params: {type: 'LONG'},
editRender: {name: 'AInputNumber', enabled: false},
},
{
title: '修改时间',
field: 'lastModifiedDate',
minWidth: 140,
visible: true,
treeNode: false,
params: {type: 'ZONED_DATE_TIME'},
formatter: ({cellValue}) => (cellValue ? dayjs(cellValue).format('YYYY-MM-DD hh:mm:ss') : ''),
},
];
}
2.5.7 前端列表搜索表单配置
javascript
const searchForm = (): any[] =>
{
return [
{
title: '创建者Id',
field: 'createdBy',
componentType: 'Text',
value: '',
type: 'Long',
operator: '',
span: 8,
componentProps: {},
},
{
title: '创建时间',
field: 'createdDate',
componentType: 'DateTime',
operator: '',
span: 8,
type: 'ZonedDateTime',
componentProps: {type: 'date', format: 'YYYY-MM-DD hh:mm:ss', style: 'width: 100%'},
},
{
title: '修改者Id',
field: 'lastModifiedBy',
componentType: 'Text',
value: '',
type: 'Long',
operator: '',
span: 8,
componentProps: {},
},
{
title: '修改时间',
field: 'lastModifiedDate',
componentType: 'DateTime',
operator: '',
span: 8,
type: 'ZonedDateTime',
componentProps: {type: 'date', format: 'YYYY-MM-DD hh:mm:ss', style: 'width: 100%'},
},
];
}
2.5.8 受影响的前端文件还有查看详情文件
2.6 @skipSoftDelete注解
此注解功能是取消本实体的逻辑删除功能,当然前提是系统生成时选择了使用逻辑删除功能。
此注解没有参数。True/False型注解。
示例:
md
@skipSoftDelete
entity User {}
2.7 @skipWebButton(listAdd-listEdit-listDetail-listDelete)注解
取消前端部分功能按钮,使用-
分隔,
md
listAdd: 取消列表中新增按钮
listEdit:取消列表中编辑按钮
listDetail:取消列表中查看详情按钮
listDelete:取消列表中删除按钮
示例:
md
@skipWebButton(listAdd-listEdit-listDetail-listDelete)
entity User {}
2.8 publicApiBy注解
根据条件生成一个开放的api接口,其中可在接口中设置简单的条件进行过滤。
支持的条件目前还比较简单,主要提供一个方法,方便手写拓展。
仅支持以下几种比较符号:
javascript
const operators = ['!=', '>=', '<=', '==', '<>', '>', '<', '='];
无任何条件的情况下,使用@publicApiBy("none")
系统中开放了/**/public接口权限。
示例:
md
@publicApiBy("available=true")
entity User {}
效果如下:
java
@GetMapping("/courses/public")
@Operation(tags = "获取课程分页列表", description = "获取课程的分页列表数据")
@AutoLog(value = "获取课程分页列表", logType = LogType.OPERATE, operateType = OperateType.LIST)
public ResponseEntity<PageRecord<CourseDTO>> getPublicCourses(
CourseCriteria criteria,
@org.springdoc.core.annotations.ParameterObject Pageable pageable
) {
log.debug("REST request to get Courses by criteria: {}", criteria);
CourseCriteria baseCriteria = new CourseCriteria();
baseCriteria.available().setEquals(true);
baseCriteria.setAnd(criteria);
IPage<CourseDTO> page;
}