优化代码生成模板

master
RuoYi 3 years ago
parent 5397e345ca
commit a1cc346aca
  1. 1
      ruoyi-framework/src/main/java/com/ruoyi/framework/manager/factory/AsyncFactory.java
  2. 3
      ruoyi-generator/src/main/java/com/ruoyi/generator/util/VelocityUtils.java
  3. 4
      ruoyi-generator/src/main/resources/vm/java/controller.java.vm
  4. 18
      ruoyi-generator/src/main/resources/vm/java/mapper.java.vm
  5. 12
      ruoyi-generator/src/main/resources/vm/java/service.java.vm
  6. 22
      ruoyi-generator/src/main/resources/vm/java/serviceImpl.java.vm
  7. 8
      ruoyi-generator/src/main/resources/vm/xml/mapper.xml.vm

@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory;
import com.ruoyi.common.constant.Constants; import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.utils.LogUtils; import com.ruoyi.common.utils.LogUtils;
import com.ruoyi.common.utils.ServletUtils; import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.ip.AddressUtils; import com.ruoyi.common.utils.ip.AddressUtils;
import com.ruoyi.common.utils.ip.IpUtils; import com.ruoyi.common.utils.ip.IpUtils;
import com.ruoyi.common.utils.spring.SpringUtils; import com.ruoyi.common.utils.spring.SpringUtils;

@ -280,7 +280,8 @@ public class VelocityUtils
*/ */
public static String getParentMenuId(JSONObject paramsObj) public static String getParentMenuId(JSONObject paramsObj)
{ {
if (StringUtils.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.PARENT_MENU_ID)) if (StringUtils.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.PARENT_MENU_ID)
&& StringUtils.isNotEmpty(paramsObj.getString(GenConstants.PARENT_MENU_ID)))
{ {
return paramsObj.getString(GenConstants.PARENT_MENU_ID); return paramsObj.getString(GenConstants.PARENT_MENU_ID);
} }

@ -76,7 +76,7 @@ public class ${ClassName}Controller extends BaseController
@GetMapping(value = "/{${pkColumn.javaField}}") @GetMapping(value = "/{${pkColumn.javaField}}")
public AjaxResult getInfo(@PathVariable("${pkColumn.javaField}") ${pkColumn.javaType} ${pkColumn.javaField}) public AjaxResult getInfo(@PathVariable("${pkColumn.javaField}") ${pkColumn.javaType} ${pkColumn.javaField})
{ {
return AjaxResult.success(${className}Service.select${ClassName}ById(${pkColumn.javaField})); return AjaxResult.success(${className}Service.select${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaField}));
} }
/** /**
@ -109,6 +109,6 @@ public class ${ClassName}Controller extends BaseController
@DeleteMapping("/{${pkColumn.javaField}s}") @DeleteMapping("/{${pkColumn.javaField}s}")
public AjaxResult remove(@PathVariable ${pkColumn.javaType}[] ${pkColumn.javaField}s) public AjaxResult remove(@PathVariable ${pkColumn.javaType}[] ${pkColumn.javaField}s)
{ {
return toAjax(${className}Service.delete${ClassName}ByIds(${pkColumn.javaField}s)); return toAjax(${className}Service.delete${ClassName}By${pkColumn.capJavaField}s(${pkColumn.javaField}s));
} }
} }

@ -17,10 +17,10 @@ public interface ${ClassName}Mapper
/** /**
* 查询${functionName} * 查询${functionName}
* *
* @param ${pkColumn.javaField} ${functionName}ID * @param ${pkColumn.javaField} ${functionName}主键
* @return ${functionName} * @return ${functionName}
*/ */
public ${ClassName} select${ClassName}ById(${pkColumn.javaType} ${pkColumn.javaField}); public ${ClassName} select${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaType} ${pkColumn.javaField});
/** /**
* 查询${functionName}列表 * 查询${functionName}列表
@ -49,27 +49,27 @@ public interface ${ClassName}Mapper
/** /**
* 删除${functionName} * 删除${functionName}
* *
* @param ${pkColumn.javaField} ${functionName}ID * @param ${pkColumn.javaField} ${functionName}主键
* @return 结果 * @return 结果
*/ */
public int delete${ClassName}ById(${pkColumn.javaType} ${pkColumn.javaField}); public int delete${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaType} ${pkColumn.javaField});
/** /**
* 批量删除${functionName} * 批量删除${functionName}
* *
* @param ${pkColumn.javaField}s 需要删除的数据ID * @param ${pkColumn.javaField}s 需要删除的数据主键集合
* @return 结果 * @return 结果
*/ */
public int delete${ClassName}ByIds(${pkColumn.javaType}[] ${pkColumn.javaField}s); public int delete${ClassName}By${pkColumn.capJavaField}s(${pkColumn.javaType}[] ${pkColumn.javaField}s);
#if($table.sub) #if($table.sub)
/** /**
* 批量删除${subTable.functionName} * 批量删除${subTable.functionName}
* *
* @param customerIds 需要删除的数据ID * @param ${pkColumn.javaField}s 需要删除的数据主键集合
* @return 结果 * @return 结果
*/ */
public int delete${subClassName}By${subTableFkClassName}s(${pkColumn.javaType}[] ${pkColumn.javaField}s); public int delete${subClassName}By${pkColumn.capJavaField}s(${pkColumn.javaType}[] ${pkColumn.javaField}s);
/** /**
* 批量新增${subTable.functionName} * 批量新增${subTable.functionName}
@ -81,7 +81,7 @@ public interface ${ClassName}Mapper
/** /**
* 通过${functionName}ID删除${subTable.functionName}信息 * 通过${functionName}主键删除${subTable.functionName}信息
* *
* @param ${pkColumn.javaField} ${functionName}ID * @param ${pkColumn.javaField} ${functionName}ID
* @return 结果 * @return 结果

@ -14,10 +14,10 @@ public interface I${ClassName}Service
/** /**
* 查询${functionName} * 查询${functionName}
* *
* @param ${pkColumn.javaField} ${functionName}ID * @param ${pkColumn.javaField} ${functionName}主键
* @return ${functionName} * @return ${functionName}
*/ */
public ${ClassName} select${ClassName}ById(${pkColumn.javaType} ${pkColumn.javaField}); public ${ClassName} select${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaType} ${pkColumn.javaField});
/** /**
* 查询${functionName}列表 * 查询${functionName}列表
@ -46,16 +46,16 @@ public interface I${ClassName}Service
/** /**
* 批量删除${functionName} * 批量删除${functionName}
* *
* @param ${pkColumn.javaField}s 需要删除的${functionName}ID * @param ${pkColumn.javaField}s 需要删除的数据主键集合
* @return 结果 * @return 结果
*/ */
public int delete${ClassName}ByIds(${pkColumn.javaType}[] ${pkColumn.javaField}s); public int delete${ClassName}By${pkColumn.capJavaField}s(${pkColumn.javaType}[] ${pkColumn.javaField}s);
/** /**
* 删除${functionName}信息 * 删除${functionName}信息
* *
* @param ${pkColumn.javaField} ${functionName}ID * @param ${pkColumn.javaField} ${functionName}主键
* @return 结果 * @return 结果
*/ */
public int delete${ClassName}ById(${pkColumn.javaType} ${pkColumn.javaField}); public int delete${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaType} ${pkColumn.javaField});
} }

@ -34,13 +34,13 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service
/** /**
* 查询${functionName} * 查询${functionName}
* *
* @param ${pkColumn.javaField} ${functionName}ID * @param ${pkColumn.javaField} ${functionName}主键
* @return ${functionName} * @return ${functionName}
*/ */
@Override @Override
public ${ClassName} select${ClassName}ById(${pkColumn.javaType} ${pkColumn.javaField}) public ${ClassName} select${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaType} ${pkColumn.javaField})
{ {
return ${className}Mapper.select${ClassName}ById(${pkColumn.javaField}); return ${className}Mapper.select${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaField});
} }
/** /**
@ -106,36 +106,36 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service
} }
/** /**
* 批量删除${functionName} * 删除${functionName}对象
* *
* @param ${pkColumn.javaField}s 需要删除的${functionName}ID * @param ${pkColumn.javaField}s 需要删除的数据主键
* @return 结果 * @return 结果
*/ */
#if($table.sub) #if($table.sub)
@Transactional @Transactional
#end #end
@Override @Override
public int delete${ClassName}ByIds(${pkColumn.javaType}[] ${pkColumn.javaField}s) public int delete${ClassName}By${pkColumn.capJavaField}s(${pkColumn.javaType}[] ${pkColumn.javaField}s)
{ {
#if($table.sub) #if($table.sub)
${className}Mapper.delete${subClassName}By${subTableFkClassName}s(${pkColumn.javaField}s); ${className}Mapper.delete${subClassName}By${subTableFkClassName}s(${pkColumn.javaField}s);
#end #end
return ${className}Mapper.delete${ClassName}ByIds(${pkColumn.javaField}s); return ${className}Mapper.delete${ClassName}By${pkColumn.capJavaField}s(${pkColumn.javaField}s);
} }
/** /**
* 删除${functionName}信息 * 删除${functionName}信息
* *
* @param ${pkColumn.javaField} ${functionName}ID * @param ${pkColumn.javaField} ${functionName}主键
* @return 结果 * @return 结果
*/ */
@Override @Override
public int delete${ClassName}ById(${pkColumn.javaType} ${pkColumn.javaField}) public int delete${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaType} ${pkColumn.javaField})
{ {
#if($table.sub) #if($table.sub)
${className}Mapper.delete${subClassName}By${subTableFkClassName}(${pkColumn.javaField}); ${className}Mapper.delete${subClassName}By${subTableFkClassName}(${pkColumn.javaField});
#end #end
return ${className}Mapper.delete${ClassName}ById(${pkColumn.javaField}); return ${className}Mapper.delete${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaField});
} }
#if($table.sub) #if($table.sub)
@ -147,7 +147,7 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service
public void insert${subClassName}(${ClassName} ${className}) public void insert${subClassName}(${ClassName} ${className})
{ {
List<${subClassName}> ${subclassName}List = ${className}.get${subClassName}List(); List<${subClassName}> ${subclassName}List = ${className}.get${subClassName}List();
Long ${pkColumn.javaField} = ${className}.get${pkColumn.capJavaField}(); ${pkColumn.javaType} ${pkColumn.javaField} = ${className}.get${pkColumn.capJavaField}();
if (StringUtils.isNotNull(${subclassName}List)) if (StringUtils.isNotNull(${subclassName}List))
{ {
List<${subClassName}> list = new ArrayList<${subClassName}>(); List<${subClassName}> list = new ArrayList<${subClassName}>();

@ -58,7 +58,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</where> </where>
</select> </select>
<select id="select${ClassName}ById" parameterType="${pkColumn.javaType}" resultMap="#if($table.sub)${ClassName}${subClassName}Result#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) #if($table.crud || $table.tree)
<include refid="select${ClassName}Vo"/> <include refid="select${ClassName}Vo"/>
where ${pkColumn.columnName} = #{${pkColumn.javaField}} where ${pkColumn.columnName} = #{${pkColumn.javaField}}
@ -102,11 +102,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where ${pkColumn.columnName} = #{${pkColumn.javaField}} where ${pkColumn.columnName} = #{${pkColumn.javaField}}
</update> </update>
<delete id="delete${ClassName}ById" parameterType="${pkColumn.javaType}"> <delete id="delete${ClassName}By${pkColumn.capJavaField}" parameterType="${pkColumn.javaType}">
delete from ${tableName} where ${pkColumn.columnName} = #{${pkColumn.javaField}} delete from ${tableName} where ${pkColumn.columnName} = #{${pkColumn.javaField}}
</delete> </delete>
<delete id="delete${ClassName}ByIds" parameterType="String"> <delete id="delete${ClassName}By${pkColumn.capJavaField}s" parameterType="String">
delete from ${tableName} where ${pkColumn.columnName} in delete from ${tableName} where ${pkColumn.columnName} in
<foreach item="${pkColumn.javaField}" collection="array" open="(" separator="," close=")"> <foreach item="${pkColumn.javaField}" collection="array" open="(" separator="," close=")">
#{${pkColumn.javaField}} #{${pkColumn.javaField}}
@ -121,7 +121,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</foreach> </foreach>
</delete> </delete>
<delete id="delete${subClassName}By${subTableFkClassName}" parameterType="Long"> <delete id="delete${subClassName}By${subTableFkClassName}" parameterType="${pkColumn.javaType}">
delete from ${subTableName} where ${subTableFkName} = #{${subTableFkclassName}} delete from ${subTableName} where ${subTableFkName} = #{${subTableFkclassName}}
</delete> </delete>

Loading…
Cancel
Save