refactor: 优化代码生成模板

pull/872/head
Jie Zheng 2025-01-15 16:44:28 +08:00
parent e62f450394
commit 4061a07850
4 changed files with 52 additions and 5 deletions

View File

@ -39,13 +39,12 @@ import ${package}.service.dto.${className}Dto;
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "${apiAlias}管理")
@Api(tags = "${apiAlias}")
@RequestMapping("/api/${changeClassName}")
public class ${className}Controller {
private final ${className}Service ${changeClassName}Service;
@Log("导出数据")
@ApiOperation("导出数据")
@GetMapping(value = "/download")
@PreAuthorize("@el.check('${changeClassName}:list')")
@ -54,7 +53,6 @@ public class ${className}Controller {
}
@GetMapping
@Log("查询${apiAlias}")
@ApiOperation("查询${apiAlias}")
@PreAuthorize("@el.check('${changeClassName}:list')")
public ResponseEntity<PageResult<${className}Dto>> query${className}(${className}QueryCriteria criteria, Pageable pageable){
@ -83,7 +81,7 @@ public class ${className}Controller {
@Log("删除${apiAlias}")
@ApiOperation("删除${apiAlias}")
@PreAuthorize("@el.check('${changeClassName}:del')")
public ResponseEntity<Object> delete${className}(@RequestBody ${pkColumnType}[] ids) {
public ResponseEntity<Object> delete${className}(@ApiParam(value = "传ID数组[]") @RequestBody ${pkColumnType}[] ids) {
${changeClassName}Service.deleteAll(ids);
return new ResponseEntity<>(HttpStatus.OK);
}

View File

@ -34,6 +34,25 @@ import java.sql.Timestamp;
<#if hasBigDecimal>
import java.math.BigDecimal;
</#if>
<#assign notBlankUsed = false>
<#assign notNullUsed = false>
<#if columns??>
<#list columns as column>
<#if column.istNotNull && column.columnKey != 'PRI'>
<#if column.columnType = 'String'>
<#assign notBlankUsed = true>
<#else>
<#assign notNullUsed = true>
</#if>
</#if>
</#list>
</#if>
<#if notBlankUsed>
import javax.validation.constraints.NotBlank;
</#if>
<#if notNullUsed>
import javax.validation.constraints.NotNull;
</#if>
import java.io.Serializable;
/**

View File

@ -42,31 +42,61 @@ public class ${className}QueryCriteria{
<#if column.queryType = '='>
/** 精确 */
@Query
<#if column.remark != ''>
@ApiModelProperty(value = "${column.remark}")
<#else>
@ApiModelProperty(value = "${column.changeColumnName}")
</#if>
private ${column.columnType} ${column.changeColumnName};
</#if>
<#if column.queryType = 'Like'>
/** 模糊 */
@Query(type = Query.Type.INNER_LIKE)
<#if column.remark != ''>
@ApiModelProperty(value = "${column.remark}")
<#else>
@ApiModelProperty(value = "${column.changeColumnName}")
</#if>
private ${column.columnType} ${column.changeColumnName};
</#if>
<#if column.queryType = '!='>
/** 不等于 */
@Query(type = Query.Type.NOT_EQUAL)
<#if column.remark != ''>
@ApiModelProperty(value = "${column.remark}")
<#else>
@ApiModelProperty(value = "${column.changeColumnName}")
</#if>
private ${column.columnType} ${column.changeColumnName};
</#if>
<#if column.queryType = 'NotNull'>
/** 不为空 */
@Query(type = Query.Type.NOT_NULL)
<#if column.remark != ''>
@ApiModelProperty(value = "${column.remark}")
<#else>
@ApiModelProperty(value = "${column.changeColumnName}")
</#if>
private ${column.columnType} ${column.changeColumnName};
</#if>
<#if column.queryType = '>='>
/** 大于等于 */
@Query(type = Query.Type.GREATER_THAN)
<#if column.remark != ''>
@ApiModelProperty(value = "${column.remark}")
<#else>
@ApiModelProperty(value = "${column.changeColumnName}")
</#if>
private ${column.columnType} ${column.changeColumnName};
</#if>
<#if column.queryType = '<='>
/** 小于等于 */
@Query(type = Query.Type.LESS_THAN)
<#if column.remark != ''>
@ApiModelProperty(value = "${column.remark}")
<#else>
@ApiModelProperty(value = "${column.changeColumnName}")
</#if>
private ${column.columnType} ${column.changeColumnName};
</#if>
</#list>

View File

@ -183,7 +183,7 @@ public class UserServiceImpl implements UserService {
public UserLoginDto getLoginData(String userName) {
User user = userRepository.findByUsername(userName);
if (user == null) {
throw new EntityNotFoundException(User.class, "name", userName);
return null;
} else {
return userLoginMapper.toDto(user);
}