mirror of
https://github.com/moshowgame/SpringBootCodeGenerator.git
synced 2025-12-26 05:48:33 +08:00
Merge pull request #172 from moshowgame/feature_template_update
Feature template update
This commit is contained in:
commit
893aa237a0
@ -244,6 +244,7 @@ ResultVo.error(message);
|
||||
# Update Logs
|
||||
| 更新日期 | 更新内容 |
|
||||
|:-----------|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| 2025.12.09 | 优化Mybatis和Mybatis-Plus模板 |
|
||||
| 2025.12.08 | 引入单元测试和JaCoCo测试覆盖率,优化代码覆盖率 [UNIT_TEST_DOCUMENT.md](UNIT_TEST_DOCUMENT.md) |
|
||||
| 2025.12.07 | 后端重构优化 ;目录结构调整! |
|
||||
| 2025.09.14 | 优化JSqlParser Engine(DDL Create SQL和Select SQL),适配更高级复杂的SQL |
|
||||
|
||||
@ -233,11 +233,11 @@ public class SqlParserServiceImpl implements SqlParserService {
|
||||
String classComment = null;
|
||||
//mysql是comment=,pgsql/oracle是comment on table,
|
||||
//2020-05-25 优化表备注的获取逻辑
|
||||
if (tableSql.contains("comment=") || tableSql.contains("comment on table")) {
|
||||
int ix = tableSql.lastIndexOf("comment=");
|
||||
if (tableSql.toLowerCase().contains("comment=") || tableSql.toLowerCase().contains("comment on table")) {
|
||||
int ix = tableSql.toLowerCase().lastIndexOf("comment=");
|
||||
String classCommentTmp = (ix > -1) ?
|
||||
tableSql.substring(ix + 8).trim() :
|
||||
tableSql.substring(tableSql.lastIndexOf("comment on table") + 17).trim();
|
||||
tableSql.substring(tableSql.toLowerCase().lastIndexOf("comment on table") + 17).trim();
|
||||
if (classCommentTmp.contains("`")) {
|
||||
classCommentTmp = classCommentTmp.substring(classCommentTmp.indexOf("`") + 1);
|
||||
classCommentTmp = classCommentTmp.substring(0, classCommentTmp.indexOf("`"));
|
||||
@ -256,11 +256,11 @@ public class SqlParserServiceImpl implements SqlParserService {
|
||||
List<FieldInfo> fieldList = new ArrayList<FieldInfo>();
|
||||
|
||||
// 正常( ) 内的一定是字段相关的定义。
|
||||
String fieldListTmp = tableSql.substring(tableSql.indexOf("(") + 1, tableSql.lastIndexOf(")"));
|
||||
String fieldListTmp = tableSql.substring(tableSql.indexOf("(") + 1, tableSql.lastIndexOf(")")).trim();
|
||||
|
||||
// 匹配 comment,替换备注里的小逗号, 防止不小心被当成切割符号切割
|
||||
String commentPattenStr1 = "comment `(.*?)\\`";
|
||||
Matcher matcher1 = Pattern.compile(commentPattenStr1).matcher(fieldListTmp);
|
||||
Matcher matcher1 = Pattern.compile(commentPattenStr1).matcher(fieldListTmp.toLowerCase());
|
||||
while (matcher1.find()) {
|
||||
|
||||
String commentTmp = matcher1.group();
|
||||
@ -305,18 +305,20 @@ public class SqlParserServiceImpl implements SqlParserService {
|
||||
// 2019-2-22 zhengkai 要在条件中使用复杂的表达式
|
||||
// 2019-4-29 zhengkai 优化对普通和特殊storage关键字的判断(感谢@AhHeadFloating的反馈 )
|
||||
// 2020-10-20 zhengkai 优化对fulltext/index关键字的处理(感谢@WEGFan的反馈)
|
||||
// 2025-12-07 zhengkai 修复对primary key的处理
|
||||
boolean notSpecialFlag = (
|
||||
!columnLine.contains("key ")
|
||||
&& !columnLine.contains("constraint")
|
||||
&& !columnLine.contains(" using ")
|
||||
&& !columnLine.contains("unique ")
|
||||
&& !columnLine.contains("fulltext ")
|
||||
&& !columnLine.contains("index ")
|
||||
&& !columnLine.contains("pctincrease")
|
||||
&& !columnLine.contains("buffer_pool")
|
||||
&& !columnLine.contains("tablespace")
|
||||
&& !(columnLine.contains("primary ") && columnLine.indexOf("storage") + 3 > columnLine.indexOf("("))
|
||||
&& !(columnLine.contains("primary ") && i > 3)
|
||||
&& !columnLine.toLowerCase().contains("constraint")
|
||||
&& !columnLine.toLowerCase().contains(" using ")
|
||||
&& !columnLine.toLowerCase().contains("unique ")
|
||||
&& !columnLine.toLowerCase().contains("fulltext ")
|
||||
&& !columnLine.toLowerCase().contains("index ")
|
||||
&& !columnLine.toLowerCase().contains("pctincrease")
|
||||
&& !columnLine.toLowerCase().contains("buffer_pool")
|
||||
&& !columnLine.toLowerCase().contains("tablespace")
|
||||
&& !(columnLine.toLowerCase().contains("primary ") && columnLine.indexOf("storage") + 3 > columnLine.indexOf("("))
|
||||
&& !(columnLine.toLowerCase().contains("primary ") && i > 3)
|
||||
&& !columnLine.toLowerCase().contains("primary key")
|
||||
);
|
||||
|
||||
if (notSpecialFlag) {
|
||||
@ -349,7 +351,10 @@ public class SqlParserServiceImpl implements SqlParserService {
|
||||
} else {
|
||||
fieldName = columnName;
|
||||
}
|
||||
columnLine = columnLine.substring(columnLine.indexOf("`") + 1).trim();
|
||||
// 修复Oracle字段名不带引号的情况
|
||||
if (columnLine.contains("`")) {
|
||||
columnLine = columnLine.substring(columnLine.indexOf("`") + 1).trim();
|
||||
}
|
||||
//2025-03-16 修复由于类型大写导致无法转换的问题
|
||||
String mysqlType = columnLine.split("\\s+")[1].toLowerCase();
|
||||
if(mysqlType.contains("(")){
|
||||
@ -372,13 +377,13 @@ public class SqlParserServiceImpl implements SqlParserService {
|
||||
}
|
||||
// field comment,MySQL的一般位于field行,而pgsql和oralce多位于后面。
|
||||
String fieldComment = null;
|
||||
if (tableSql.contains("comment on column") && (tableSql.contains("." + columnName + " is ") || tableSql.contains(".`" + columnName + "` is"))) {
|
||||
if (tableSql.toLowerCase().contains("comment on column") && (tableSql.toLowerCase().contains("." + columnName + " is ") || tableSql.toLowerCase().contains(".`" + columnName + "` is"))) {
|
||||
//新增对pgsql/oracle的字段备注支持
|
||||
//COMMENT ON COLUMN public.check_info.check_name IS '检查者名称';
|
||||
//2018-11-22 lshz0088 正则表达式的点号前面应该加上两个反斜杠,否则会认为是任意字符
|
||||
//2019-4-29 zhengkai 优化对oracle注释comment on column的支持(@liukex)
|
||||
tableSql = tableSql.replaceAll(".`" + columnName + "` is", "." + columnName + " is");
|
||||
Matcher columnCommentMatcher = Pattern.compile("\\." + columnName + " is `").matcher(tableSql);
|
||||
tableSql = tableSql.toLowerCase().replaceAll(".`" + columnName + "` is", "." + columnName + " is");
|
||||
Matcher columnCommentMatcher = Pattern.compile("\\." + columnName + " is `").matcher(tableSql.toLowerCase());
|
||||
fieldComment = columnName;
|
||||
while (columnCommentMatcher.find()) {
|
||||
String columnCommentTmp = columnCommentMatcher.group();
|
||||
@ -386,9 +391,9 @@ public class SqlParserServiceImpl implements SqlParserService {
|
||||
fieldComment = tableSql.substring(tableSql.indexOf(columnCommentTmp) + columnCommentTmp.length()).trim();
|
||||
fieldComment = fieldComment.substring(0, fieldComment.indexOf("`")).trim();
|
||||
}
|
||||
} else if (columnLine.contains(" comment")) {
|
||||
} else if (columnLine.toLowerCase().contains(" comment")) {
|
||||
//20200518 zhengkai 修复包含comment关键字的问题
|
||||
String commentTmp = columnLine.substring(columnLine.lastIndexOf("comment") + 7).trim();
|
||||
String commentTmp = columnLine.toLowerCase().substring(columnLine.toLowerCase().lastIndexOf("comment") + 7).trim();
|
||||
// '用户ID',
|
||||
if (commentTmp.contains("`") || commentTmp.indexOf("`") != commentTmp.lastIndexOf("`")) {
|
||||
commentTmp = commentTmp.substring(commentTmp.indexOf("`") + 1, commentTmp.lastIndexOf("`"));
|
||||
@ -398,6 +403,9 @@ public class SqlParserServiceImpl implements SqlParserService {
|
||||
commentTmp = commentTmp.substring(0, commentTmp.lastIndexOf(")") + 1);
|
||||
}
|
||||
fieldComment = commentTmp;
|
||||
} else if (columnLine.contains("--")) {
|
||||
// 支持Oracle风格的注释(--)
|
||||
fieldComment = columnLine.substring(columnLine.indexOf("--") + 2).trim();
|
||||
} else {
|
||||
//修复comment不存在导致报错的问题
|
||||
fieldComment = columnName;
|
||||
@ -416,10 +424,10 @@ public class SqlParserServiceImpl implements SqlParserService {
|
||||
}
|
||||
}
|
||||
|
||||
if (fieldList.size() < 1) {
|
||||
if (fieldList.isEmpty()) {
|
||||
throw new Exception("表结构分析失败,请检查语句或者提交issue给我");
|
||||
}
|
||||
|
||||
//build Class Info
|
||||
ClassInfo codeJavaInfo = new ClassInfo();
|
||||
codeJavaInfo.setTableName(tableName);
|
||||
codeJavaInfo.setClassName(className);
|
||||
|
||||
@ -27,6 +27,7 @@ public final class mysqlJavaTypeUtil {
|
||||
//字符串
|
||||
mysqlJavaTypeMap.put("char","String");
|
||||
mysqlJavaTypeMap.put("varchar","String");
|
||||
mysqlJavaTypeMap.put("varchar2","String"); // Oracle类型
|
||||
mysqlJavaTypeMap.put("tinytext","String");
|
||||
mysqlJavaTypeMap.put("text","String");
|
||||
mysqlJavaTypeMap.put("mediumtext","String");
|
||||
@ -35,6 +36,8 @@ public final class mysqlJavaTypeUtil {
|
||||
mysqlJavaTypeMap.put("date","Date");
|
||||
mysqlJavaTypeMap.put("datetime","Date");
|
||||
mysqlJavaTypeMap.put("timestamp","Date");
|
||||
// 数字类型 - Oracle增强
|
||||
mysqlJavaTypeMap.put("number","BigDecimal"); // Oracle的NUMBER类型默认映射为BigDecimal,支持精度
|
||||
|
||||
|
||||
mysqlSwaggerTypeMap.put("bigint","integer");
|
||||
@ -46,7 +49,10 @@ public final class mysqlJavaTypeUtil {
|
||||
mysqlSwaggerTypeMap.put("boolean","boolean");
|
||||
mysqlSwaggerTypeMap.put("float","number");
|
||||
mysqlSwaggerTypeMap.put("double","number");
|
||||
mysqlSwaggerTypeMap.put("decimal","Double");
|
||||
mysqlSwaggerTypeMap.put("decimal","number");
|
||||
// Oracle类型
|
||||
mysqlSwaggerTypeMap.put("varchar2","string");
|
||||
mysqlSwaggerTypeMap.put("number","number");
|
||||
}
|
||||
|
||||
public static HashMap<String, String> getMysqlJavaTypeMap() {
|
||||
|
||||
@ -43,11 +43,11 @@ public class ${classInfo.className}Controller {
|
||||
if(old${classInfo.className}!=null){
|
||||
${classInfo.className?uncap_first}Mapper.updateById(${classInfo.className?uncap_first});
|
||||
}else{
|
||||
if(${classInfo.className?uncap_first}Mapper.selectOne(new QueryWrapper<${classInfo.className}>().eq("${classInfo.className?uncap_first}_name",${classInfo.className?uncap_first}.get${classInfo.className}Name()))!=null){
|
||||
return ${returnUtilFailure}("保存失败,名字重复");
|
||||
}
|
||||
${classInfo.className?uncap_first}.setCreateTime(new Date());
|
||||
${classInfo.className?uncap_first}Mapper.insert(${classInfo.className?uncap_first});
|
||||
if(${classInfo.className?uncap_first}Mapper.selectOne(new QueryWrapper<${classInfo.className}>().eq("${classInfo.className?uncap_first}_name",${classInfo.className?uncap_first}.get${classInfo.className}Name()))!=null){
|
||||
return ${returnUtilFailure}("保存失败,名字重复");
|
||||
}
|
||||
${classInfo.className?uncap_first}.setCreateTime(new Date());
|
||||
${classInfo.className?uncap_first}Mapper.insert(${classInfo.className?uncap_first});
|
||||
}
|
||||
return ${returnUtilSuccess}("保存成功");
|
||||
}
|
||||
@ -83,43 +83,51 @@ public class ${classInfo.className}Controller {
|
||||
* 自动分页查询
|
||||
*/
|
||||
@PostMapping("/list")
|
||||
public Object list(String searchParams,
|
||||
@RequestParam(required = false, defaultValue = "0") int page,
|
||||
@RequestParam(required = false, defaultValue = "10") int limit) {
|
||||
public Object list(@RequestBody ${classInfo.className} ${classInfo.className?uncap_first},@RequestParam(required = false, defaultValue = "0") int page,@RequestParam(required = false, defaultValue = "10") int limit) {
|
||||
log.info("page:"+page+"-limit:"+limit+"-json:"+ JSON.toJSONString(searchParams));
|
||||
//分页构造器
|
||||
Page<${classInfo.className}> buildPage = new Page<${classInfo.className}>(page,limit);
|
||||
//条件构造器
|
||||
QueryWrapper<${classInfo.className}> queryWrapper = new QueryWrapper<${classInfo.className}>();
|
||||
if(StringUtils.isNotEmpty(searchParams)&&JSON.isValid(searchParams)) {
|
||||
${classInfo.className} ${classInfo.className?uncap_first} = JSON.parseObject(searchParams, ${classInfo.className}.class);
|
||||
queryWrapper.eq(StringUtils.isNoneEmpty(${classInfo.className?uncap_first}.get${classInfo.className}Name()), "${classInfo.className?uncap_first}_name", ${classInfo.className?uncap_first}.get${classInfo.className}Name());
|
||||
if(JSON.stringify(${classInfo.className?uncap_first}).length()>2) {
|
||||
//自行删除不需要动态查询字段
|
||||
queryWrapper.
|
||||
<#list classInfo.fieldList as fieldItem>
|
||||
eq(StringUtils.isNoneEmpty(${classInfo.className?uncap_first}.get${fieldItem.fieldName}()), "${fieldItem.fieldName}", ${classInfo.className?uncap_first}.get${fieldItem.fieldName}())
|
||||
</#list>
|
||||
;
|
||||
}
|
||||
//执行分页
|
||||
IPage<${classInfo.className}> pageList = ${classInfo.className?uncap_first}Mapper.selectPage(buildPage, queryWrapper);
|
||||
//返回结果
|
||||
return ${returnUtil}.PAGE(pageList.getRecords(),pageList.getTotal());
|
||||
}
|
||||
|
||||
/**
|
||||
* 手工分页查询(按需使用)
|
||||
* 动态条件手工分页查询
|
||||
* 根据对象属性自动构建条件,如果字段有值则进行分页+指定条件查询,否则仅进行分页查询
|
||||
*/
|
||||
/*@PostMapping("/list2")
|
||||
public Object list2(String searchParams,
|
||||
@RequestParam(required = false, defaultValue = "0") int page,
|
||||
@RequestParam(required = false, defaultValue = "10") int limit) {
|
||||
log.info("searchParams:"+ JSON.toJSONString(searchParams));
|
||||
//通用模式
|
||||
${classInfo.className} queryParamDTO = JSON.parseObject(searchParams, ${classInfo.className}.class);
|
||||
//专用DTO模式
|
||||
//QueryParamDTO queryParamDTO = JSON.parseObject(searchParams, QueryParamDTO.class);
|
||||
//queryParamDTO.setPage((page - 1)* limit);
|
||||
//queryParamDTO.setLimit(limit);
|
||||
//(page - 1) * limit, limit
|
||||
List<${classInfo.className}> itemList = ${classInfo.className?uncap_first}Mapper.pageAll(queryParamDTO,(page - 1)* limit,limit);
|
||||
Integer itemCount = ${classInfo.className?uncap_first}Mapper.countAll(queryParamDTO);
|
||||
@PostMapping("/list")
|
||||
public Object list(String searchParams, @RequestParam(required = false, defaultValue = "1") int page, @RequestParam(required = false, defaultValue = "10") int limit) {
|
||||
log.info("page:"+page+"-limit:"+limit+"-json:"+ JSON.toJSONString(searchParams));
|
||||
|
||||
// 分页参数处理
|
||||
int offset = (page - 1) * limit;
|
||||
|
||||
// 查询参数处理
|
||||
${classInfo.className} queryParamDTO = new ${classInfo.className}();
|
||||
if(StringUtils.isNotEmpty(searchParams) && JSON.isValid(searchParams)) {
|
||||
queryParamDTO = JSON.parseObject(searchParams, ${classInfo.className}.class);
|
||||
}
|
||||
|
||||
// 使用动态条件查询
|
||||
List<${classInfo.className}> itemList = ${classInfo.className?uncap_first}Mapper.selectPageByCondition(queryParamDTO, offset, limit);
|
||||
int itemCount = ${classInfo.className?uncap_first}Mapper.selectPageByConditionCount(queryParamDTO);
|
||||
|
||||
//返回结果
|
||||
return ${returnUtilSuccess}.PAGE(itemList,itemCount);
|
||||
}*/
|
||||
return ${returnUtil}.PAGE(itemList, itemCount);
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
public ModelAndView listPage(){
|
||||
return new ModelAndView("${classInfo.className?uncap_first}-list");
|
||||
@ -132,16 +140,16 @@ public class ${classInfo.className}Controller {
|
||||
}
|
||||
|
||||
/**
|
||||
* 发布/暂停(如不需要请屏蔽)
|
||||
* 激活/停用(如不需要请屏蔽)
|
||||
*/
|
||||
@PostMapping("/publish")
|
||||
public Object publish(int id,Integer status){
|
||||
@PostMapping("/active")
|
||||
public Object active(int id,Integer status){
|
||||
${classInfo.className} ${classInfo.className?uncap_first} = ${classInfo.className?uncap_first}Mapper.selectOne(new QueryWrapper<${classInfo.className}>().eq("${classInfo.className?uncap_first}_id",id));
|
||||
if(${classInfo.className?uncap_first}!=null){
|
||||
${classInfo.className?uncap_first}.setUpdateTime(new Date());
|
||||
${classInfo.className?uncap_first}.setStatus(status);
|
||||
${classInfo.className?uncap_first}Mapper.updateById(${classInfo.className?uncap_first});
|
||||
return ${returnUtilSuccess}((status==1)?"已发布":"已暂停");
|
||||
return ${returnUtilSuccess}((status==1)?"已激活":"已停用");
|
||||
}else if(status.equals(${classInfo.className?uncap_first}.getStatus())){
|
||||
return ${returnUtilFailure}("状态不正确");
|
||||
}else{
|
||||
@ -150,13 +158,13 @@ public class ${classInfo.className}Controller {
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行(如不需要请屏蔽)
|
||||
* 测试(如不需要请屏蔽)
|
||||
*/
|
||||
@PostMapping("/execute")
|
||||
public Object execute(){
|
||||
@GetMapping("/test")
|
||||
public Object test(){
|
||||
return ${returnUtilSuccess};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@ import io.swagger.v3.oas.annotations.media.Schema;</#if>
|
||||
* @date ${.now?string('yyyy-MM-dd')}
|
||||
*/
|
||||
<#if isLombok?exists && isLombok==true>@Data</#if><#if isSwagger?exists && isSwagger==true>
|
||||
@Schema"${classInfo.classComment}")</#if>
|
||||
@Schema(description = "${classInfo.classComment}")</#if>
|
||||
public class ${classInfo.className} implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
<#if isAutoImport?exists && isAutoImport==true>
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import ${packageName}.entity.${classInfo.className};
|
||||
import java.util.List;
|
||||
@ -14,25 +15,55 @@ import java.util.List;
|
||||
@Mapper
|
||||
public interface ${classInfo.className}Mapper extends BaseMapper<${classInfo.className}> {
|
||||
|
||||
@Select(
|
||||
"<script>select t0.* from ${classInfo.tableName} t0 " +
|
||||
//add here if need left join
|
||||
"where 1=1" +
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
"<when test='${fieldItem.fieldName}!=null and ${fieldItem.fieldName}!='' '> and t0.${fieldItem.columnName}=井{${fieldItem.fieldName}}</when> " +
|
||||
</#list>
|
||||
//add here if need page limit
|
||||
//" limit ¥{page},¥{limit} " +
|
||||
" </script>")
|
||||
List<${classInfo.className}> pageAll(${classInfo.className} queryParamDTO,int page,int limit);
|
||||
/**
|
||||
* 动态条件分页查询 - 根据对象属性自动构建条件
|
||||
* 如果字段有值则进行分页+指定条件查询,否则仅进行分页查询
|
||||
*/
|
||||
@Select("""
|
||||
<script>
|
||||
SELECT * FROM ${classInfo.tableName}
|
||||
<where>
|
||||
<#list classInfo.fieldList as fieldItem>
|
||||
<#if fieldItem.fieldClass?contains("String")>
|
||||
<if test='queryParamDTO.${fieldItem.fieldName} != null and queryParamDTO.${fieldItem.fieldName} != ""'>
|
||||
AND ${fieldItem.columnName} = 井{queryParamDTO.${fieldItem.fieldName}}
|
||||
</if>
|
||||
<#else>
|
||||
<if test='queryParamDTO.${fieldItem.fieldName} != null'>
|
||||
AND ${fieldItem.columnName} = 井{queryParamDTO.${fieldItem.fieldName}}
|
||||
</if>
|
||||
</#if>
|
||||
</#list>
|
||||
</where>
|
||||
ORDER BY id DESC
|
||||
LIMIT 井{offset}, 井{limit}
|
||||
</script>
|
||||
""")
|
||||
List<${classInfo.className}> selectPageByCondition(@Param("queryParamDTO") ${classInfo.className} queryParamDTO,
|
||||
@Param("offset") int offset,
|
||||
@Param("limit") int limit);
|
||||
|
||||
@Select("<script>select count(1) from ${classInfo.tableName} t0 " +
|
||||
//add here if need left join
|
||||
"where 1=1" +
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
"<when test='${fieldItem.fieldName}!=null and ${fieldItem.fieldName}!='' '> and t0.${fieldItem.columnName}=井{${fieldItem.fieldName}}</when> " +
|
||||
</#list>
|
||||
" </script>")
|
||||
int countAll(${classInfo.className} queryParamDTO);
|
||||
/**
|
||||
* 动态条件分页查询总数
|
||||
*/
|
||||
@Select("""
|
||||
<script>
|
||||
SELECT COUNT(*) FROM ${classInfo.tableName}
|
||||
<where>
|
||||
<#list classInfo.fieldList as fieldItem>
|
||||
<#if fieldItem.fieldClass?contains("String")>
|
||||
<if test='queryParamDTO.${fieldItem.fieldName} != null and queryParamDTO.${fieldItem.fieldName} != ""'>
|
||||
AND ${fieldItem.columnName} = 井{queryParamDTO.${fieldItem.fieldName}}
|
||||
</if>
|
||||
<#else>
|
||||
<if test='queryParamDTO.${fieldItem.fieldName} != null'>
|
||||
AND ${fieldItem.columnName} = 井{queryParamDTO.${fieldItem.fieldName}}
|
||||
</if>
|
||||
</#if>
|
||||
</#list>
|
||||
</where>
|
||||
</script>
|
||||
""")
|
||||
int selectPageByConditionCount(@Param("queryParamDTO") ${classInfo.className} queryParamDTO);
|
||||
|
||||
}
|
||||
|
||||
@ -57,9 +57,9 @@ public class ${classInfo.className}Controller {
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy/MM/dd')}
|
||||
**/
|
||||
@RequestMapping("/load")
|
||||
public Object load(int id){
|
||||
return ${classInfo.className?uncap_first}Service.load(id);
|
||||
@RequestMapping("/find")
|
||||
public Object find(int id){
|
||||
return ${classInfo.className?uncap_first}Service.find(id);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -73,4 +73,34 @@ public class ${classInfo.className}Controller {
|
||||
return ${classInfo.className?uncap_first}Service.pageList(offset, pagesize);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询 动态条件分页查询 - 根据对象属性自动构建条件
|
||||
* 如果字段有值则进行分页+指定条件查询,否则仅进行分页查询
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy/MM/dd')}
|
||||
**/
|
||||
@RequestMapping("/pageByCondition")
|
||||
public Map<String, Object> pageByCondition(${classInfo.className} queryParamDTO,
|
||||
@RequestParam(required = false, defaultValue = "0") int offset,
|
||||
@RequestParam(required = false, defaultValue = "10") int pagesize) {
|
||||
return ${classInfo.className?uncap_first}Service.pageByCondition(queryParamDTO, offset, pagesize);
|
||||
}
|
||||
|
||||
/**
|
||||
* 激活/停用
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy/MM/dd')}
|
||||
**/
|
||||
@RequestMapping("/active")
|
||||
public Object active(int id, Integer status) {
|
||||
${classInfo.className} ${classInfo.className?uncap_first} = ${classInfo.className?uncap_first}Service.find(id);
|
||||
if(${classInfo.className?uncap_first} != null) {
|
||||
${classInfo.className?uncap_first}.setStatus(status);
|
||||
Object result = ${classInfo.className?uncap_first}Service.update(${classInfo.className?uncap_first});
|
||||
return result;
|
||||
} else {
|
||||
return ${returnUtilFailure}("未找到记录");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -40,7 +40,7 @@ public interface ${classInfo.className}Mapper {
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy/MM/dd')}
|
||||
**/
|
||||
${classInfo.className} load(int id);
|
||||
${classInfo.className} find(int id);
|
||||
|
||||
/**
|
||||
* 查询 分页查询
|
||||
|
||||
@ -13,23 +13,33 @@ import java.util.List;
|
||||
@Repository
|
||||
public interface ${classInfo.className}Mapper {
|
||||
|
||||
@Select("select * from ${classInfo.tableName} where ${classInfo.tableName}_id=井{id}")
|
||||
public ${classInfo.className} getById(Integer id);
|
||||
@Select("""
|
||||
select * from ${classInfo.tableName} where ${classInfo.tableName}_id=井{id}
|
||||
""")
|
||||
public ${classInfo.className} find(Integer id);
|
||||
|
||||
@Options(useGeneratedKeys=true,keyProperty="${classInfo.className?uncap_first}Id")
|
||||
@Insert("insert into ${classInfo.tableName}" +
|
||||
" (<#list classInfo.fieldList as fieldItem >${fieldItem.columnName}<#if fieldItem_has_next>,</#if></#list>)" +
|
||||
" values(<#list classInfo.fieldList as fieldItem >${fieldItem.fieldName}<#if fieldItem_has_next>,<#else>)</#if></#list>")
|
||||
@Insert("""
|
||||
insert into ${classInfo.tableName} (
|
||||
<#list classInfo.fieldList as fieldItem >${fieldItem.columnName}<#if fieldItem_has_next>,</#if></#list>
|
||||
) values (
|
||||
<#list classInfo.fieldList as fieldItem >井{${fieldItem.fieldName}}<#if fieldItem_has_next>,<#else>)</#if></#list>
|
||||
)
|
||||
""")
|
||||
public Integer insert(${classInfo.className} ${classInfo.className?uncap_first});
|
||||
|
||||
@Delete(value = "delete from ${classInfo.tableName} where ${classInfo.tableName}_id=井{${classInfo.className?uncap_first}Id}")
|
||||
@Delete("""
|
||||
delete from ${classInfo.tableName} where ${classInfo.tableName}_id=井{id}
|
||||
""")
|
||||
boolean delete(Integer id);
|
||||
|
||||
@Update(value = "update ${classInfo.tableName} set "
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
<#if fieldItem.columnName != "id">+" ${fieldItem.columnName}=井{${fieldItem.fieldName}}<#if fieldItem_has_next>,</#if>"</#if>
|
||||
</#list>
|
||||
+" where ${classInfo.tableName}_id=井{${classInfo.className?uncap_first}Id} ")
|
||||
@Update("""
|
||||
update ${classInfo.tableName} set
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
<#if fieldItem.columnName != "id">${fieldItem.columnName}=井{${fieldItem.fieldName}}<#if fieldItem_has_next>,</#if></#if>
|
||||
</#list>
|
||||
where ${classInfo.tableName}_id=井{id}
|
||||
""")
|
||||
boolean update(${classInfo.className} ${classInfo.className?uncap_first});
|
||||
|
||||
|
||||
@ -38,19 +48,73 @@ public interface ${classInfo.className}Mapper {
|
||||
@Result(property = "${fieldItem.fieldName}", column = "${fieldItem.columnName}")<#if fieldItem_has_next>,</#if>
|
||||
</#list>
|
||||
})
|
||||
@Select(value = "select * from ${classInfo.tableName} where ${classInfo.tableName}_id=井{queryParam}")
|
||||
${classInfo.className} selectOne(String queryParam);
|
||||
@Select("""
|
||||
select * from ${classInfo.tableName} where ${classInfo.tableName}_id=井{id}
|
||||
""")
|
||||
${classInfo.className} selectOne(Integer id);
|
||||
|
||||
@Results(value = {
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
@Result(property = "${fieldItem.fieldName}", column = "${fieldItem.columnName}")<#if fieldItem_has_next>,</#if>
|
||||
</#list>
|
||||
})
|
||||
@Select(value = "select * from ${classInfo.tableName} where "
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
+" ${fieldItem.columnName}=井{${fieldItem.fieldName}}<#if fieldItem_has_next> or </#if>"
|
||||
</#list>
|
||||
)
|
||||
@Select("""
|
||||
select * from ${classInfo.tableName} where
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
${fieldItem.columnName}=井{${fieldItem.fieldName}}<#if fieldItem_has_next> or </#if>
|
||||
</#list>
|
||||
""")
|
||||
List<${classInfo.className}> selectList(${classInfo.className} ${classInfo.className?uncap_first});
|
||||
|
||||
/**
|
||||
* 动态条件分页查询 - 根据对象属性自动构建条件
|
||||
* 如果字段有值则进行分页+指定条件查询,否则仅进行分页查询
|
||||
*/
|
||||
@Select("""
|
||||
<script>
|
||||
SELECT * FROM ${classInfo.tableName}
|
||||
<where>
|
||||
<#list classInfo.fieldList as fieldItem>
|
||||
<#if fieldItem.fieldClass?contains("String")>
|
||||
<if test='queryParamDTO.${fieldItem.fieldName} != null and queryParamDTO.${fieldItem.fieldName} != ""'>
|
||||
AND ${fieldItem.columnName} = 井{queryParamDTO.${fieldItem.fieldName}}
|
||||
</if>
|
||||
<#else>
|
||||
<if test='queryParamDTO.${fieldItem.fieldName} != null'>
|
||||
AND ${fieldItem.columnName} = 井{queryParamDTO.${fieldItem.fieldName}}
|
||||
</if>
|
||||
</#if>
|
||||
</#list>
|
||||
</where>
|
||||
ORDER BY id DESC
|
||||
LIMIT 井{offset}, 井{limit}
|
||||
</script>
|
||||
""")
|
||||
List<${classInfo.className}> pageByCondition(@Param("queryParamDTO") ${classInfo.className} queryParamDTO,
|
||||
@Param("offset") int offset,
|
||||
@Param("limit") int limit);
|
||||
|
||||
/**
|
||||
* 动态条件分页查询总数
|
||||
*/
|
||||
@Select("""
|
||||
<script>
|
||||
SELECT COUNT(*) FROM ${classInfo.tableName}
|
||||
<where>
|
||||
<#list classInfo.fieldList as fieldItem>
|
||||
<#if fieldItem.fieldClass?contains("String")>
|
||||
<if test='queryParamDTO.${fieldItem.fieldName} != null and queryParamDTO.${fieldItem.fieldName} != ""'>
|
||||
AND ${fieldItem.columnName} = 井{queryParamDTO.${fieldItem.fieldName}}
|
||||
</if>
|
||||
<#else>
|
||||
<if test='queryParamDTO.${fieldItem.fieldName} != null'>
|
||||
AND ${fieldItem.columnName} = 井{queryParamDTO.${fieldItem.fieldName}}
|
||||
</if>
|
||||
</#if>
|
||||
</#list>
|
||||
</where>
|
||||
</script>
|
||||
""")
|
||||
int pageByConditionCount(@Param("queryParamDTO") ${classInfo.className} queryParamDTO);
|
||||
|
||||
}
|
||||
@ -26,11 +26,17 @@ public interface ${classInfo.className}Service {
|
||||
/**
|
||||
* 根据主键 id 查询
|
||||
*/
|
||||
public ${classInfo.className} load(int id);
|
||||
public ${classInfo.className} find(int id);
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*/
|
||||
public Map<String,Object> pageList(int offset, int pagesize);
|
||||
|
||||
/**
|
||||
* 动态条件分页查询 - 根据对象属性自动构建条件
|
||||
* 如果字段有值则进行分页+指定条件查询,否则仅进行分页查询
|
||||
*/
|
||||
public Map<String,Object> pageByCondition(${classInfo.className} queryParamDTO, int offset, int pagesize);
|
||||
|
||||
}
|
||||
|
||||
@ -46,8 +46,8 @@ public class ${classInfo.className}ServiceImpl implements ${classInfo.className}
|
||||
|
||||
|
||||
@Override
|
||||
public ${classInfo.className} load(int id) {
|
||||
return ${classInfo.className?uncap_first}Mapper.load(id);
|
||||
public ${classInfo.className} find(int id) {
|
||||
return ${classInfo.className?uncap_first}Mapper.find(id);
|
||||
}
|
||||
|
||||
|
||||
@ -65,4 +65,18 @@ public class ${classInfo.className}ServiceImpl implements ${classInfo.className}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String,Object> pageByCondition(${classInfo.className} queryParamDTO, int offset, int pagesize) {
|
||||
|
||||
List<${classInfo.className}> pageList = ${classInfo.className?uncap_first}Mapper.pageByCondition(queryParamDTO, offset, pagesize);
|
||||
int totalCount = ${classInfo.className?uncap_first}Mapper.pageByConditionCount(queryParamDTO);
|
||||
|
||||
// result
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
result.put("pageList", pageList);
|
||||
result.put("totalCount", totalCount);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user