Browse Source

2023-12-6 代码生成器修改,增加swagger注解

develop
zhousq 11 months ago
parent
commit
d1886d1b8e
  1. 53
      lzbi-generator/src/main/resources/vm/java/controller.java.vm
  2. 2
      lzbi-generator/src/main/resources/vm/java/domain.java.vm
  3. 28
      lzbi-generator/src/main/resources/vm/java/mapper.java.vm
  4. 58
      lzbi-generator/src/main/resources/vm/java/service.java.vm
  5. 2
      lzbi-generator/src/main/resources/vm/java/sub-domain.java.vm
  6. 20
      lzbi-generator/src/main/resources/vm/xml/mapper.xml.vm

53
lzbi-generator/src/main/resources/vm/java/controller.java.vm

@ -16,7 +16,7 @@ import com.lzbi.common.annotation.Log;
import com.lzbi.common.core.controller.BaseController;
import com.lzbi.common.core.domain.AjaxResult;
import com.lzbi.common.enums.BusinessType;
import ${packageName}.domain.${ClassName}Dao;
import ${packageName}.domain. ${ClassName};
import ${packageName}.service.${ClassName}Service;
import com.lzbi.common.utils.poi.ExcelUtil;
#if($table.crud || $table.sub)
@ -40,19 +40,23 @@ public class ${ClassName}Controller extends BaseController
/**
* 查询${functionName}列表
*/
@ApiOperation("查询${functionName}列表")
@ApiImplicitParams({
@ApiImplicitParam(name = "${ClassName}", value = "", dataType = "${ClassName}", dataTypeClass = ${ClassName}.class),
})
@PreAuthorize("@ss.hasPermi('${permissionPrefix}:list')")
@GetMapping("/list")
#if($table.crud || $table.sub)
public TableDataInfo list(${ClassName}Dao ${className}Dao)
public TableDataInfo list(${ClassName} ${ClassName})
{
startPage();
List<${ClassName}Dao> list = ${className}Service.select${ClassName}DaoList(${className}Dao);
List< ${ClassName}> list = ${className}Service.select ${ClassName}List(${ClassName});
return getDataTable(list);
}
#elseif($table.tree)
public AjaxResult list(${ClassName}Dao ${className}Dao)
public AjaxResult list(${ClassName} ${ClassName})
{
List<${ClassName}Dao> list = ${className}Service.select${ClassName}DaoList(${className}Dao);
List< ${ClassName}> list = ${className}Service.select ${ClassName}List(${ClassName});
return success(list);
}
#end
@ -60,56 +64,77 @@ public class ${ClassName}Controller extends BaseController
/**
* 导出${functionName}列表
*/
@ApiOperation("导出${functionName}列表")
@ApiImplicitParams({
@ApiImplicitParam(name = "${ClassName}", value = "", dataType = "${ClassName}", dataTypeClass = ${ClassName}.class),
})
@PreAuthorize("@ss.hasPermi('${permissionPrefix}:export')")
@Log(title = "${functionName}", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, ${ClassName}Dao ${className}Dao)
public void export(HttpServletResponse response, ${ClassName} ${ClassName})
{
List<${ClassName}Dao> list = ${className}Service.select${ClassName}DaoList(${className}Dao);
ExcelUtil<${ClassName}Dao> util = new ExcelUtil<${ClassName}Dao>(${ClassName}Dao.class);
List< ${ClassName}> list = ${className}Service.select ${ClassName}List(${ClassName});
ExcelUtil< ${ClassName}> util = new ExcelUtil<(${ClassName}>(${ClassName}.class);
util.exportExcel(response, list, "${functionName}数据");
}
/**
* 获取${functionName}详细信息
*/
@ApiOperation("获取${functionName}详细信息")
@ApiImplicitParams({
@ApiImplicitParam(name = "${pkColumn.javaField}", value = "", dataType = "${pkColumn.javaType}", dataTypeClass = ${pkColumn.javaType}.class),
})
@PreAuthorize("@ss.hasPermi('${permissionPrefix}:query')")
@GetMapping(value = "/{${pkColumn.javaField}}")
public AjaxResult getInfo(@PathVariable("${pkColumn.javaField}") ${pkColumn.javaType} ${pkColumn.javaField})
{
return success(${className}Service.select${ClassName}DaoBy${pkColumn.capJavaField}(${pkColumn.javaField}));
return success(${className}Service.select${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaField}));
}
/**
* 新增${functionName}
*/
@ApiOperation("新增${functionName}")
@ApiImplicitParams({
@ApiImplicitParam(name = "${ClassName}", value = "", dataType = "${ClassName}", dataTypeClass = ${ClassName}.class),
})
@PreAuthorize("@ss.hasPermi('${permissionPrefix}:add')")
@Log(title = "${functionName}", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody ${ClassName}Dao ${className}Dao)
public AjaxResult add(@RequestBody ${ClassName} ${ClassName})
{
return toAjax(${className}Service.insert${ClassName}Dao(${className}Dao));
return toAjax(${className}Service.insert${ClassName}(${ClassName}));
}
/**
* 修改${functionName}
*/
@ApiOperation("修改${functionName}")
@ApiImplicitParams({
@ApiImplicitParam(name = "${ClassName}", value = "", dataType = "${ClassName}", dataTypeClass = ${ClassName}.class),
})
@PreAuthorize("@ss.hasPermi('${permissionPrefix}:edit')")
@Log(title = "${functionName}", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody ${ClassName}Dao ${className}Dao)
public AjaxResult edit(@RequestBody ${ClassName} ${ClassName})
{
return toAjax(${className}Service.update${ClassName}Dao(${className}Dao));
return toAjax(${className}Service.update${ClassName}(${ClassName}));
}
/**
* 删除${functionName}
*/
@ApiOperation("删除${functionName}")
@ApiImplicitParams({
@ApiImplicitParam(name = "${pkColumn.javaField}s", value = "", dataType = "${pkColumn.javaType}", dataTypeClass =${pkColumn.javaType}.class),
})
@PreAuthorize("@ss.hasPermi('${permissionPrefix}:remove')")
@Log(title = "${functionName}", businessType = BusinessType.DELETE)
@DeleteMapping("/{${pkColumn.javaField}s}")
public AjaxResult remove(@PathVariable ${pkColumn.javaType}[] ${pkColumn.javaField}s)
{
return toAjax(${className}Service.delete${ClassName}DaoBy${pkColumn.capJavaField}s(${pkColumn.javaField}s));
return toAjax(${className}Service.delete${ClassName}By${pkColumn.capJavaField}s(${pkColumn.javaField}s));
}
}

2
lzbi-generator/src/main/resources/vm/java/domain.java.vm

@ -25,7 +25,7 @@ import com.lzbi.common.core.domain.TreeEntity;
#set($Entity="TreeEntity")
#end
@Data
public class ${ClassName}Dao extends ${Entity}
public class ${ClassName} extends ${Entity}
{
private static final long serialVersionUID = 1L;

28
lzbi-generator/src/main/resources/vm/java/mapper.java.vm

@ -1,10 +1,10 @@
package ${packageName}.mapper;
import java.util.List;
import ${packageName}.domain.${ClassName}Dao;
import ${packageName}.domain.${ClassName};
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
#if($table.sub)
import ${packageName}.domain.${subClassName}Dao;
import ${packageName}.domain.${subClassName};
#end
/**
@ -14,7 +14,7 @@ import ${packageName}.domain.${subClassName}Dao;
* @date ${datetime}
*/
public interface ${ClassName}Mapper extends BaseMapper<${ClassName}Dao>
public interface ${ClassName}Mapper extends BaseMapper<${ClassName}>
{
/**
* 查询${functionName}
@ -22,23 +22,23 @@ public interface ${ClassName}Mapper extends BaseMapper<${ClassName}Dao>
* @param ${pkColumn.javaField} ${functionName}主键
* @return ${functionName}
*/
public ${ClassName}Dao select${ClassName}DaoBy${pkColumn.capJavaField}(${pkColumn.javaType} ${pkColumn.javaField});
public ${ClassName} select${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaType} ${pkColumn.javaField});
/**
* 查询${functionName}列表
*
* @param ${className}Dao ${functionName}
* @param ${className} ${functionName}
* @return ${functionName}集合
*/
public List<${ClassName}Dao> select${ClassName}DaoList(${ClassName}Dao ${className}Dao);
public List<${ClassName}> select${ClassName}List(${ClassName} ${className});
/**
* 新增${functionName}
*
* @param ${className}Dao ${functionName}
* @param ${className} ${functionName}
* @return 结果
*/
public int insert${ClassName}Dao(${ClassName}Dao ${className}Dao);
public int insert${ClassName}(${ClassName} ${className});
/**
* 修改${functionName}
@ -46,7 +46,7 @@ public interface ${ClassName}Mapper extends BaseMapper<${ClassName}Dao>
* @param ${className} ${functionName}
* @return 结果
*/
public int update${ClassName}Dao(${ClassName}Dao ${className}Dao);
public int update${ClassName}(${ClassName} ${className});
/**
* 删除${functionName}
@ -54,7 +54,7 @@ public interface ${ClassName}Mapper extends BaseMapper<${ClassName}Dao>
* @param ${pkColumn.javaField} ${functionName}主键
* @return 结果
*/
public int delete${ClassName}DaoBy${pkColumn.capJavaField}(${pkColumn.javaType} ${pkColumn.javaField});
public int delete${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaType} ${pkColumn.javaField});
/**
* 批量删除${functionName}
@ -62,7 +62,7 @@ public interface ${ClassName}Mapper extends BaseMapper<${ClassName}Dao>
* @param ${pkColumn.javaField}s 需要删除的数据主键集合
* @return 结果
*/
public int delete${ClassName}DaoBy${pkColumn.capJavaField}s(${pkColumn.javaType}[] ${pkColumn.javaField}s);
public int delete${ClassName}By${pkColumn.capJavaField}s(${pkColumn.javaType}[] ${pkColumn.javaField}s);
#if($table.sub)
/**
@ -71,7 +71,7 @@ public interface ${ClassName}Mapper extends BaseMapper<${ClassName}Dao>
* @param ${pkColumn.javaField}s 需要删除的数据主键集合
* @return 结果
*/
public int delete${subClassName}DaoBy${subTableFkClassName}Daos(${pkColumn.javaType}[] ${pkColumn.javaField}s);
public int delete${subClassName}By${subTableFkClassName}Daos(${pkColumn.javaType}[] ${pkColumn.javaField}s);
/**
* 批量新增${subTable.functionName}
@ -79,7 +79,7 @@ public interface ${ClassName}Mapper extends BaseMapper<${ClassName}Dao>
* @param ${subclassName}DaoList ${subTable.functionName}列表
* @return 结果
*/
public int batch${subClassName}Dao(List<${subClassName}Dao> ${subclassName}DaoList);
public int batch${subClassName}(List<${subClassName}> ${subclassName}DaoList);
/**
@ -88,6 +88,6 @@ public interface ${ClassName}Mapper extends BaseMapper<${ClassName}Dao>
* @param ${pkColumn.javaField} ${functionName}ID
* @return 结果
*/
public int delete${subClassName}DaoBy${subTableFkClassName}Dao(${pkColumn.javaType} ${pkColumn.javaField});
public int delete${subClassName}By${subTableFkClassName}Dao(${pkColumn.javaType} ${pkColumn.javaField});
#end
}

58
lzbi-generator/src/main/resources/vm/java/service.java.vm

@ -12,9 +12,9 @@ import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.lzbi.common.utils.DateUtils;
import org.springframework.transaction.annotation.Transactional;
import ${packageName}.domain.${subClassName}Dao;
import ${packageName}.domain.${subClassName};
#end
import ${packageName}.domain.${ClassName}Dao;
import ${packageName}.domain.${ClassName};
import ${packageName}.mapper.${ClassName}Mapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@ -25,7 +25,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
* @date ${datetime}
*/
@Service
public class ${ClassName}Service extends ServiceImpl<${ClassName}Mapper, ${ClassName}Dao> implements IService<${ClassName}Dao>
public class ${ClassName}Service extends ServiceImpl<${ClassName}Mapper, ${ClassName}> implements IService<${ClassName}>
{
/**
@ -34,70 +34,70 @@ public class ${ClassName}Service extends ServiceImpl<${ClassName}Mapper, ${Class
* @param ${pkColumn.javaField} ${functionName}主键
* @return ${functionName}
*/
public ${ClassName}Dao select${ClassName}DaoBy${pkColumn.capJavaField}(${pkColumn.javaType} ${pkColumn.javaField})
public ${ClassName} select${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaType} ${pkColumn.javaField})
{
return baseMapper.select${ClassName}DaoBy${pkColumn.capJavaField}(${pkColumn.javaField});
return baseMapper.select${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaField});
}
/**
* 查询${functionName}列表
*
* @param ${className}Dao ${functionName}
* @param ${className} ${functionName}
* @return ${functionName}
*/
public List<${ClassName}Dao> select${ClassName}DaoList(${ClassName}Dao ${className}Dao)
public List<${ClassName}> select${ClassName}List(${ClassName} ${className})
{
return baseMapper.select${ClassName}DaoList(${className}Dao);
return baseMapper.select${ClassName}List(${className});
}
/**
* 新增${functionName}
*
* @param ${className}Dao ${functionName}
* @param ${className} ${functionName}
* @return 结果
*/
#if($table.sub)
@Transactional
#end
public int insert${ClassName}Dao(${ClassName}Dao ${className}Dao)
public int insert${ClassName}(${ClassName} ${className})
{
#foreach ($column in $columns)
#if($column.javaField == 'createdTime')
${className}Dao.setCreatedTime(DateUtils.getNowDate());
${className}.setCreatedTime(DateUtils.getNowDate());
#end
#end
#if($table.sub)
int rows = baseMapper.insert${ClassName}Dao(${className}Dao);
insert${subClassName}Dao(${className}Dao);
int rows = baseMapper.insert${ClassName}(${className});
insert${subClassName}(${className});
return rows;
#else
return baseMapper.insert${ClassName}Dao(${className}Dao);
return baseMapper.insert${ClassName}(${className});
#end
}
/**
* 修改${functionName}
*
* @param ${className}Dao ${functionName}
* @param ${className} ${functionName}
* @return 结果
*/
#if($table.sub)
@Transactional
#end
public int update${ClassName}Dao(${ClassName}Dao ${className}Dao)
public int update${ClassName}(${ClassName} ${className})
{
#foreach ($column in $columns)
#if($column.javaField == 'updatedTime')
${className}Dao.setUpdatedTime(DateUtils.getNowDate());
${className}.setUpdatedTime(DateUtils.getNowDate());
#end
#end
#if($table.sub)
baseMapper.delete${subClassName}By${subTableFkClassName}(${className}Dao.get${pkColumn.capJavaField}());
insert${subClassName}Dao(${className}Dao);
baseMapper.delete${subClassName}By${subTableFkClassName}(${className}.get${pkColumn.capJavaField}());
insert${subClassName}(${className});
#end
return baseMapper.update${ClassName}Dao(${className}Dao);
return baseMapper.update${ClassName}(${className});
}
/**
@ -110,12 +110,12 @@ public class ${ClassName}Service extends ServiceImpl<${ClassName}Mapper, ${Class
@Transactional
#end
public int delete${ClassName}DaoBy${pkColumn.capJavaField}s(${pkColumn.javaType}[] ${pkColumn.javaField}s)
public int delete${ClassName}By${pkColumn.capJavaField}s(${pkColumn.javaType}[] ${pkColumn.javaField}s)
{
#if($table.sub)
baseMapper.delete${subClassName}By${subTableFkClassName}s(${pkColumn.javaField}s);
#end
return baseMapper.delete${ClassName}DaoBy${pkColumn.capJavaField}s(${pkColumn.javaField}s);
return baseMapper.delete${ClassName}By${pkColumn.capJavaField}s(${pkColumn.javaField}s);
}
/**
@ -128,28 +128,28 @@ public class ${ClassName}Service extends ServiceImpl<${ClassName}Mapper, ${Class
@Transactional
#end
public int delete${ClassName}DaoBy${pkColumn.capJavaField}(${pkColumn.javaType} ${pkColumn.javaField})
public int delete${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaType} ${pkColumn.javaField})
{
#if($table.sub)
baseMapper.delete${subClassName}By${subTableFkClassName}(${pkColumn.javaField});
#end
return baseMapper.delete${ClassName}DaoBy${pkColumn.capJavaField}(${pkColumn.javaField});
return baseMapper.delete${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaField});
}
#if($table.sub)
/**
* 新增${subTable.functionName}信息
*
* @param ${className}Dao ${functionName}对象
* @param ${className} ${functionName}对象
*/
public void insert${subClassName}Dao(${ClassName}Dao ${className}Dao)
public void insert${subClassName}(${ClassName} ${className})
{
List<${subClassName}Dao> ${subclassName}DaoList = ${className}Dao.get${subClassName}DaoList();
List<${subClassName}> ${subclassName}DaoList = ${className}.get${subClassName}List();
${pkColumn.javaType} ${pkColumn.javaField} = ${className}.get${pkColumn.capJavaField}();
if (StringUtils.isNotNull(${subclassName}DaoList))
{
List<${subClassName}Dao> list = new ArrayList<${subClassName}Dao>();
for (${subClassName}Dao ${subclassName}Dao : ${subclassName}DaoList)
List<${subClassName}> list = new ArrayList<${subClassName}>();
for (${subClassName} ${subclassName}Dao : ${subclassName}DaoList)
{
${subclassName}Dao.set${subTableFkClassName}(${pkColumn.javaField});
list.add(${subclassName}Dao);

2
lzbi-generator/src/main/resources/vm/java/sub-domain.java.vm

@ -14,7 +14,7 @@ import com.lzbi.module.base.BaseModuleEntity;
* @author ${author}
* @date ${datetime}
*/
public class ${subClassName}Dao extends BaseModuleEntity
public class ${subClassName} extends BaseModuleEntity
{
private static final long serialVersionUID = 1L;

20
lzbi-generator/src/main/resources/vm/xml/mapper.xml.vm

@ -4,18 +4,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${packageName}.mapper.${ClassName}Mapper">
<resultMap type="${packageName}.domain.${ClassName}Dao" id="${ClassName}Result">
<resultMap type="${packageName}.domain.${ClassName}" id="${ClassName}Result">
#foreach ($column in $columns)
<result property="${column.javaField}" column="${column.columnName}" />
#end
</resultMap>
#if($table.sub)
<resultMap id="${ClassName}${subClassName}DaoResult" type="${ClassName}Dao" extends="${ClassName}Result">
<collection property="${subclassName}DaoList" notNullColumn="sub_${subTable.pkColumn.columnName}" javaType="java.util.List" resultMap="${subClassName}Result" />
<resultMap id="${ClassName}${subClassName}Result" type="${ClassName}" extends="${ClassName}Result">
<collection property="${subclassName}List" notNullColumn="sub_${subTable.pkColumn.columnName}" javaType="java.util.List" resultMap="${subClassName}Result" />
</resultMap>
<resultMap type="${subClassName}Dao" id="${subClassName}Result">
<resultMap type="${subClassName}" id="${subClassName}Result">
#foreach ($column in $subTable.columns)
<result property="${column.javaField}" column="sub_${column.columnName}" />
#end
@ -26,7 +26,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select#foreach($column in $columns) $column.columnName#if($foreach.count != $columns.size()),#end#end from ${tableName}
</sql>
<select id="select${ClassName}DaoList" parameterType="${ClassName}Dao" resultMap="${ClassName}Result">
<select id="select${ClassName}List" parameterType="${ClassName}" resultMap="${ClassName}Result">
<include refid="select${ClassName}Vo"/>
<where>
#foreach($column in $columns)
@ -58,7 +58,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</where>
</select>
<select id="select${ClassName}DaoBy${pkColumn.capJavaField}" parameterType="${pkColumn.javaType}" resultMap="#if($table.sub)${ClassName}${subClassName}DaoResult#else${ClassName}Result#end">
<select id="select${ClassName}By${pkColumn.capJavaField}" parameterType="${pkColumn.javaType}" resultMap="#if($table.sub)${ClassName}${subClassName}Result#else${ClassName}Result#end">
#if($table.crud || $table.tree)
<include refid="select${ClassName}Vo"/>
where ${pkColumn.columnName} = #{${pkColumn.javaField}}
@ -72,7 +72,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#end
</select>
<insert id="insert${ClassName}Dao" parameterType="${ClassName}Dao"#if($pkColumn.increment) useGeneratedKeys="true" keyProperty="$pkColumn.javaField"#end>
<insert id="insert${ClassName}" parameterType="${ClassName}"#if($pkColumn.increment) useGeneratedKeys="true" keyProperty="$pkColumn.javaField"#end>
insert into ${tableName}
<trim prefix="(" suffix=")" suffixOverrides=",">
#foreach($column in $columns)
@ -90,7 +90,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</trim>
</insert>
<update id="update${ClassName}Dao" parameterType="${ClassName}Dao">
<update id="update${ClassName}" parameterType="${ClassName}">
update ${tableName}
<trim prefix="SET" suffixOverrides=",">
#foreach($column in $columns)
@ -102,11 +102,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where ${pkColumn.columnName} = #{${pkColumn.javaField}}
</update>
<delete id="delete${ClassName}DaoBy${pkColumn.capJavaField}" parameterType="${pkColumn.javaType}">
<delete id="delete${ClassName}By${pkColumn.capJavaField}" parameterType="${pkColumn.javaType}">
delete from ${tableName} where ${pkColumn.columnName} = #{${pkColumn.javaField}}
</delete>
<delete id="delete${ClassName}DaoBy${pkColumn.capJavaField}s" parameterType="String">
<delete id="delete${ClassName}By${pkColumn.capJavaField}s" parameterType="String">
delete from ${tableName} where ${pkColumn.columnName} in
<foreach item="${pkColumn.javaField}" collection="array" open="(" separator="," close=")">
#{${pkColumn.javaField}}

Loading…
Cancel
Save