代码生成修改。1. 合并add.html和edit.html为form.html; 2. 修改controller通过id获取对象@ModelAttribute; 3. remove对象时,逻辑删除非物理删除,查询对象时查询未逻辑删除的对象;3. 修改对象时,对每个值进行修改,而非不等于空修改,这样保证不然出现修改某个值为空时,不起效果。
This commit is contained in:
parent
2f535082f2
commit
9d5199f6b1
|
|
@ -0,0 +1,61 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
|
||||
<meta charset="utf-8">
|
||||
<head th:include="include :: header"></head>
|
||||
<body class="white-bg">
|
||||
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
|
||||
<form class="form-horizontal m" id="form-${classname}-edit" th:object="${${classname}}">
|
||||
<input id="${primaryKey.attrname}" name="${primaryKey.attrname}" th:field="*{${primaryKey.attrname}}" type="hidden">
|
||||
#foreach($column in $columns)
|
||||
#if($column.columnName != $primaryKey.columnName)
|
||||
#if(!${column.configInfo})
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">${column.columnComment}:</label>
|
||||
<div class="col-sm-8">
|
||||
<input id="${column.attrname}" name="${column.attrname}" th:field="*{${column.attrname}}" class="form-control" type="text">
|
||||
</div>
|
||||
</div>
|
||||
#else
|
||||
#if(${column.configInfo.type} == "dict")
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">${column.columnComment}:</label>
|
||||
<div class="col-sm-8">
|
||||
<select name="${column.attrname}" class="form-control m-b" th:with="type=${@dict.getType('${column.configInfo.value}')}">
|
||||
<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{${column.attrname}}"></option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
#elseif(${column.configInfo.type} == "date")
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">${column.columnComment}:</label>
|
||||
<div class="col-sm-8">
|
||||
<input id="${column.attrname}" name="${column.attrname}" th:field="*{${column.attrname}}" class="form-control time-input" type="text">
|
||||
</div>
|
||||
</div>
|
||||
#elseif(${column.configInfo.type} == "fk")
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
</form>
|
||||
</div>
|
||||
<div th:include="include::footer"></div>
|
||||
<script type="text/javascript">
|
||||
var prefix = ctx + "${moduleName}/${classname}";
|
||||
$("#form-${classname}-edit").validate({
|
||||
rules:{
|
||||
xxxx:{
|
||||
required:true,
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
function submitHandler() {
|
||||
if ($.validate.form()) {
|
||||
|
||||
$.operate.save(prefix + "/save", $('#form-${classname}-edit').serialize());
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -79,8 +79,8 @@
|
|||
$(function() {
|
||||
var options = {
|
||||
url: prefix + "/list",
|
||||
createUrl: prefix + "/add",
|
||||
updateUrl: prefix + "/edit/{id}",
|
||||
createUrl: prefix + "/form",
|
||||
updateUrl: prefix + "/form?id={id}",
|
||||
removeUrl: prefix + "/remove",
|
||||
exportUrl: prefix + "/export",
|
||||
modalName: "${tableComment}",
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
package ${basePackage}.web.controller.${moduleName};
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import java.util.List;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
|
@ -17,7 +20,7 @@ import ${package}.service.I${className}Service;
|
|||
import com.ruoyi.framework.web.base.BaseController;
|
||||
import com.ruoyi.common.page.TableDataInfo;
|
||||
import com.ruoyi.common.base.AjaxResult;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
|
||||
/**
|
||||
* ${tableComment} 信息操作处理
|
||||
|
|
@ -34,6 +37,19 @@ public class ${className}Controller extends BaseController
|
|||
@Autowired
|
||||
private I${className}Service ${classname}Service;
|
||||
|
||||
@ModelAttribute("${classname}")
|
||||
public ${className} get(@RequestParam(required=false) ${primaryKey.attrType} ${primaryKey.attrname}) {
|
||||
#if(${primaryKey.attrType}=='String')
|
||||
if(StringUtils.isNotBlank(${primaryKey.attrname})) {
|
||||
#else
|
||||
if (${primaryKey.attrname}!=null){
|
||||
#end
|
||||
return ${classname}Service.select${className}ById(${primaryKey.attrname});
|
||||
}else{
|
||||
return new ${className}();
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresPermissions("${moduleName}:${classname}:view")
|
||||
@GetMapping()
|
||||
public String ${classname}()
|
||||
|
|
@ -69,17 +85,17 @@ public class ${className}Controller extends BaseController
|
|||
}
|
||||
|
||||
/**
|
||||
* 新增${tableComment}
|
||||
* 表单${tableComment}
|
||||
*/
|
||||
@GetMapping("/add")
|
||||
public String add()
|
||||
@GetMapping("/form")
|
||||
public String form(${className} ${classname})
|
||||
{
|
||||
return prefix + "/add";
|
||||
return prefix + "/form";
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增保存${tableComment}
|
||||
*/
|
||||
|
||||
@RequiresPermissions("${moduleName}:${classname}:add")
|
||||
@Log(title = "${tableComment}", businessType = BusinessType.INSERT)
|
||||
@PostMapping("/add")
|
||||
|
|
@ -88,10 +104,10 @@ public class ${className}Controller extends BaseController
|
|||
{
|
||||
return toAjax(${classname}Service.insert${className}(${classname}));
|
||||
}
|
||||
|
||||
*/
|
||||
/**
|
||||
* 修改${tableComment}
|
||||
*/
|
||||
|
||||
@GetMapping("/edit/{${primaryKey.attrname}}")
|
||||
public String edit(@PathVariable("${primaryKey.attrname}") ${primaryKey.attrType} ${primaryKey.attrname}, ModelMap mmap)
|
||||
{
|
||||
|
|
@ -99,17 +115,24 @@ public class ${className}Controller extends BaseController
|
|||
mmap.put("${classname}", ${classname});
|
||||
return prefix + "/edit";
|
||||
}
|
||||
|
||||
*/
|
||||
/**
|
||||
* 修改保存${tableComment}
|
||||
*/
|
||||
@RequiresPermissions("${moduleName}:${classname}:edit")
|
||||
@Log(title = "${tableComment}", businessType = BusinessType.UPDATE)
|
||||
@PostMapping("/edit")
|
||||
@PostMapping("/save")
|
||||
@ResponseBody
|
||||
public AjaxResult editSave(${className} ${classname})
|
||||
public AjaxResult save(${className} ${classname})
|
||||
{
|
||||
return toAjax(${classname}Service.update${className}(${classname}));
|
||||
#if(${primaryKey.attrType}=='String')
|
||||
if(StringUtils.isBlank(${classname}.get${primaryKey.attrname}()))
|
||||
#else
|
||||
if (${classname}.get${primaryKey.attrName}()==null)
|
||||
#end
|
||||
return toAjax(${classname}Service.insert${className}(${classname}));
|
||||
else
|
||||
return toAjax(${classname}Service.update${className}(${classname}));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
|
||||
<select id="select${className}List" parameterType="${className}" resultMap="${className}Result">
|
||||
<include refid="select${className}Vo"/>
|
||||
<where>
|
||||
<where> del_flag = '0'
|
||||
#foreach($column in $columns)
|
||||
<if test="$column.attrname != null #if($column.attrType == 'String' ) and $column.attrname.trim() != '' #end"> and $column.columnName = #{$column.attrname}</if>
|
||||
#end
|
||||
|
|
@ -25,7 +25,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
|
||||
<select id="select${className}ById" parameterType="${primaryKey.attrType}" resultMap="${className}Result">
|
||||
<include refid="select${className}Vo"/>
|
||||
where ${primaryKey.columnName} = #{${primaryKey.attrname}}
|
||||
where del_flag = '0' and ${primaryKey.columnName} = #{${primaryKey.attrname}}
|
||||
</select>
|
||||
|
||||
<insert id="insert${className}" parameterType="${className}"#if($primaryKey.extra == 'auto_increment') useGeneratedKeys="true" keyProperty="$primaryKey.attrname"#end>
|
||||
|
|
@ -33,14 +33,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
#foreach($column in $columns)
|
||||
#if($column.columnName != $primaryKey.columnName || $primaryKey.extra != 'auto_increment')
|
||||
#if($column.attrname=='createTime'||$column.attrname=='updateTime')
|
||||
$column.columnName,
|
||||
#else
|
||||
<if test="$column.attrname != null #if($column.attrType == 'String' ) and $column.attrname != '' #end ">$column.columnName,</if>
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
#foreach($column in $columns)
|
||||
#if($column.columnName != $primaryKey.columnName || $primaryKey.extra != 'auto_increment')
|
||||
#if($column.attrname=='createTime'||$column.attrname=='updateTime')
|
||||
sysDate(),
|
||||
#else
|
||||
<if test="$column.attrname != null #if($column.attrType == 'String' ) and $column.attrname != '' #end ">#{$column.attrname},</if>
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
</trim>
|
||||
|
|
@ -51,22 +59,27 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<trim prefix="SET" suffixOverrides=",">
|
||||
#foreach($column in $columns)
|
||||
#if($column.columnName != $primaryKey.columnName)
|
||||
<if test="$column.attrname != null #if($column.attrType == 'String' ) and $column.attrname != '' #end ">$column.columnName = #{$column.attrname},</if>
|
||||
#if($column.attrname=='updateTime')
|
||||
$column.columnName=sysDate(),
|
||||
#else
|
||||
$column.columnName = #{$column.attrname},
|
||||
#end
|
||||
|
||||
#end
|
||||
#end
|
||||
</trim>
|
||||
where ${primaryKey.columnName} = #{${primaryKey.attrname}}
|
||||
</update>
|
||||
|
||||
<delete id="delete${className}ById" parameterType="${primaryKey.attrType}">
|
||||
delete from ${tableName} where ${primaryKey.columnName} = #{${primaryKey.attrname}}
|
||||
</delete>
|
||||
<update id="delete${className}ById" parameterType="${primaryKey.attrType}">
|
||||
update ${tableName} set del_flag = '2' where ${primaryKey.columnName} = #{${primaryKey.attrname}}
|
||||
</update>
|
||||
|
||||
<delete id="delete${className}ByIds" parameterType="String">
|
||||
delete from ${tableName} where ${primaryKey.columnName} in
|
||||
<update id="delete${className}ByIds" parameterType="String">
|
||||
update ${tableName} set del_flag = '2' where ${primaryKey.columnName} in
|
||||
<foreach item="${primaryKey.attrname}" collection="array" open="(" separator="," close=")">
|
||||
#{${primaryKey.attrname}}
|
||||
</foreach>
|
||||
</delete>
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue