Skip to content

Commit

Permalink
feat(tool/generator): 代码生成 Request 实体时,针对字符串类型增加数据长度校验注解
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles7c committed Jan 6, 2024
1 parent e3e958b commit ee82558
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ public class FieldConfigDO implements Serializable {
@NotBlank(message = "列类型不能为空")
private String columnType;

/**
* 列大小
*/
@Schema(description = "列大小", example = "255")
private Long columnSize;

/**
* 字段名称
*/
Expand Down Expand Up @@ -147,6 +153,7 @@ public FieldConfigDO(@NonNull Column column) {
this.tableName = column.getTableName();
this.setColumnName(column.getName());
this.setColumnType(columnType);
this.setColumnSize(column.getSize());
this.setComment(column.getComment());
this.setIsRequired(isRequired);
this.setShowInList(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ public List<FieldConfigDO> listFieldConfig(String tableName, Boolean requireSync
Collection<Column> columnList = MetaUtils.getColumns(dataSource, tableName);
return columnList.stream().map(FieldConfigDO::new).collect(Collectors.toList());
}

// 同步最新数据表列信息
if (requireSync) {
Collection<Column> columnList = MetaUtils.getColumns(dataSource, tableName);
Expand All @@ -155,6 +154,7 @@ public List<FieldConfigDO> listFieldConfig(String tableName, Boolean requireSync
String columnType =
StrUtil.splitToArray(column.getTypeName(), StringConstants.SPACE)[0].toLowerCase();
fieldConfig.setColumnType(columnType);
fieldConfig.setColumnSize(column.getSize());
fieldConfig.setComment(column.getComment());
} else {
// 新增字段配置
Expand Down Expand Up @@ -193,7 +193,6 @@ public void saveConfig(GenConfigReq req, String tableName) {
fieldConfig.setTableName(tableName);
}
fieldConfigMapper.insertBatch(fieldConfigList);

// 保存或更新生成配置信息
GenConfigDO newGenConfig = req.getGenConfig();
String frontendPath = newGenConfig.getFrontendPath();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import lombok.Data;

import io.swagger.v3.oas.annotations.media.Schema;

import org.hibernate.validator.constraints.Length;

import top.charles7c.continew.starter.extension.crud.base.BaseReq;

/**
Expand Down Expand Up @@ -45,6 +47,9 @@ public class ${className} extends BaseReq {
@NotNull(message = "${fieldConfig.comment}不能为空")
</#if>
</#if>
<#if fieldConfig.fieldType = 'String' && fieldConfig.columnSize??>
@Length(max = ${fieldConfig.columnSize}, message = "${fieldConfig.comment}长度不能超过 {max} 个字符")
</#if>
private ${fieldConfig.fieldType} ${fieldConfig.fieldName};
</#if>
</#list>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
<template #icon><icon-edit /></template>修改
</a-button>
<a-popconfirm
content="确定要删除当前选中的数据吗"
content="是否确定删除该数据"
type="warning"
@ok="handleDelete([record.id])"
>
Expand Down Expand Up @@ -421,7 +421,7 @@
proxy.$modal.warning({
title: '警告',
titleAlign: 'start',
content: '确定要删除当前选中的数据吗?',
content: `是否确定删除所选的${r'${ids.value.length}'}条数据?`,
hideCancel: false,
onOk: () => {
handleDelete(ids.value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ CREATE TABLE IF NOT EXISTS `gen_field_config` (
`table_name` varchar(64) NOT NULL COMMENT '表名称',
`column_name` varchar(64) NOT NULL COMMENT '列名称',
`column_type` varchar(25) NOT NULL COMMENT '列类型',
`column_size` bigint(20) DEFAULT NULL COMMENT '列大小',
`field_name` varchar(64) NOT NULL COMMENT '字段名称',
`field_type` varchar(25) NOT NULL COMMENT '字段类型',
`comment` varchar(512) DEFAULT NULL COMMENT '注释',
Expand Down

0 comments on commit ee82558

Please sign in to comment.