判空修改

This commit is contained in:
20932067@zju.edu.cn 2021-06-03 12:02:09 +08:00
parent 6f08e9e37f
commit bb859aa36a
10 changed files with 74 additions and 51 deletions

View File

@ -3,7 +3,7 @@ import request from '@/utils/request'
// 查询校验规则列表 // 查询校验规则列表
export function listRegular(query) { export function listRegular(query) {
return request({ return request({
url: '/tool/regular/list', url: '/tool/regular/option',
method: 'get', method: 'get',
params: query params: query
}) })

View File

@ -84,9 +84,11 @@
<el-table-column label="是否正则" min-width="10%"> <el-table-column label="是否正则" min-width="10%">
<template slot-scope="scope"> <template slot-scope="scope">
<el-select v-model="scope.row.isRegular"> <el-select v-model="scope.row.isRegular">
<el-option v-for="item in regularOptions" :key="item.id" <el-option v-for="item in regularOptions"
:key="item.id"
:label="item.name" :label="item.name"
:value="item.id" /> :value="item.id" />
<span></span>
</el-select> </el-select>
</template> </template>
</el-table-column> </el-table-column>
@ -169,6 +171,7 @@ export default {
}; };
}, },
created() { created() {
this.getRegularList()
const tableId = this.$route.params && this.$route.params.tableId; const tableId = this.$route.params && this.$route.params.tableId;
if (tableId) { if (tableId) {
// //
@ -185,7 +188,6 @@ export default {
getMenuTreeselect().then(response => { getMenuTreeselect().then(response => {
this.menus = this.handleTree(response.data, "menuId"); this.menus = this.handleTree(response.data, "menuId");
}); });
this.getRegularList()
} }
}, },
methods: { methods: {

View File

@ -87,8 +87,8 @@ spring:
redis: redis:
# 地址 # 地址
# host: 114.215.82.135 # host: 114.215.82.135
host: 127.0.0.1 # host: 127.0.0.1
# host: 13.70.28.14 host: 13.70.28.14
# 端口默认为6379 # 端口默认为6379
port: 6379 port: 6379
# 密码 # 密码

View File

@ -61,6 +61,27 @@ public class RegularController extends GenBaseController {
return AjaxResult.error(GenReturnConstants.SYS_ERROR); return AjaxResult.error(GenReturnConstants.SYS_ERROR);
} }
} }
/**
* 查询校验规则列表
*
* @return
*/
@PreAuthorize("@ebts.hasPermi('tool:regular:option')")
@GetMapping("/option")
public Serializable option() {
try {
startPage();
GenServerResult<List<Regular>> genServerResult = regularService.selectRegularOption();
if (genServerResult.isStart()) {
return getDataTable(genServerResult.getData());
} else {
return AjaxResult.info(genServerResult.getMsg());
}
} catch (RuntimeException e) {
logger.error(e.getMessage());
return AjaxResult.error(GenReturnConstants.SYS_ERROR);
}
}
/** /**
* 导出校验规则列表 * 导出校验规则列表

View File

@ -26,6 +26,12 @@ public interface RegularDao {
* @return 校验规则集合 * @return 校验规则集合
*/ */
List<Regular> selectRegularList(Regular regular); List<Regular> selectRegularList(Regular regular);
/**
* 查询校验规则下拉框列表
*
* @return 校验规则集合
*/
List<Regular> selectRegularOption();
/** /**
* 新增校验规则 * 新增校验规则

View File

@ -27,6 +27,12 @@ public interface RegularService {
* @return 校验规则集合 * @return 校验规则集合
*/ */
GenServerResult<List<Regular>> selectRegularList(Regular regular); GenServerResult<List<Regular>> selectRegularList(Regular regular);
/**
* 查询校验规则下拉框列表
*
* @return 校验规则集合
*/
GenServerResult<List<Regular>> selectRegularOption();
/** /**
* 新增校验规则 * 新增校验规则

View File

@ -68,6 +68,25 @@ public class RegularServiceImpl implements RegularService {
return new GenServerResult<>(false, GenReturnConstants.DB_EX); return new GenServerResult<>(false, GenReturnConstants.DB_EX);
} }
} }
/**
* 查询校验规则下拉框列表
*
* @return 校验规则
*/
@Override
public GenServerResult<List<Regular>> selectRegularOption() {
try {
List<Regular> regulars = regularDao.selectRegularOption();
if (regulars.size() > 0) {
return new GenServerResult<>(true, regulars);
} else {
return new GenServerResult<>(false, GenReturnConstants.RESULT_EMPTY);
}
} catch (RuntimeException e) {
logger.error(e.getMessage());
return new GenServerResult<>(false, GenReturnConstants.DB_EX);
}
}
/** /**
* 新增校验规则 * 新增校验规则

View File

@ -23,13 +23,16 @@
<select id="selectRegularList" parameterType="Regular" resultMap="RegularResult"> <select id="selectRegularList" parameterType="Regular" resultMap="RegularResult">
<include refid="selectRegularVo"/> <include refid="selectRegularVo"/>
<where> <where>
and id != 1 <if test="1=1">and id != 1</if>
<if test="name != null and name != ''"> and name like concat('%', #{name}, '%')</if> <if test="name != null and name != ''"> and name like concat('%', #{name}, '%')</if>
<if test="regular != null and regular != ''"> and regular like concat('%', #{regular}, '%')</if> <if test="regular != null and regular != ''"> and regular like concat('%', #{regular}, '%')</if>
<if test="validation != null and validation != ''"> and validation like concat('%', #{validation}, '%')</if> <if test="validation != null and validation != ''"> and validation like concat('%', #{validation}, '%')</if>
<if test="enable != null "> and enable = #{enable}</if> <if test="enable != null "> and enable = #{enable}</if>
</where> </where>
</select> </select>
<select id="selectRegularOption" parameterType="Regular" resultMap="RegularResult">
select id ,name from gen_regular where enable = 1
</select>
<select id="selectRegularById" parameterType="Long" resultMap="RegularResult"> <select id="selectRegularById" parameterType="Long" resultMap="RegularResult">
<include refid="selectRegularVo"/> <include refid="selectRegularVo"/>

View File

@ -15,6 +15,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.PutMapping;
@ -128,28 +129,7 @@ public class ${ClassName}Controller extends EBTSController {
@PreAuthorize("@ebts.hasPermi('${permissionPrefix}:add')") @PreAuthorize("@ebts.hasPermi('${permissionPrefix}:add')")
@Log(title = "${functionName}", businessType = BusinessType.INSERT) @Log(title = "${functionName}", businessType = BusinessType.INSERT)
@PostMapping @PostMapping
public AjaxResult add(@RequestBody ${ClassName} ${className}) { public AjaxResult add(@Validated @RequestBody ${ClassName} ${className}) {
#foreach ($column in $columns)
#if($column.isRequired == 1)
#if($column.javaField.length() > 2 && $column.javaField.substring(1,2).matches("[A-Z]"))
#set($AttrName=$column.javaField)
#else
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
#end
#if($column.javaType.equals("String"))
if (${className}.get${AttrName}() == null || ${className}.get${AttrName}().equals("")) {
#elseif($column.javaType.equals("Integer")||$column.javaType.equals("Long"))
if (${className}.get${AttrName}() == null || ${className}.get${AttrName}()<0) {
#end
return AjaxResult.error("${column.columnComment}不能为空!");
}
#end
#if($column.isRegular != 1)
if (!Pattern.matches("${column.regular}",${className}.get${AttrName}())){
return AjaxResult.error("${column.columnComment}格式错误!");
}
#end
#end
try { try {
ServerResult<Integer> genServerResult = ${className}Service.insert${ClassName}(${className}); ServerResult<Integer> genServerResult = ${className}Service.insert${ClassName}(${className});
if (genServerResult.isStart()) { if (genServerResult.isStart()) {
@ -171,30 +151,8 @@ public class ${ClassName}Controller extends EBTSController {
@PreAuthorize("@ebts.hasPermi('${permissionPrefix}:edit')") @PreAuthorize("@ebts.hasPermi('${permissionPrefix}:edit')")
@Log(title = "${functionName}", businessType = BusinessType.UPDATE) @Log(title = "${functionName}", businessType = BusinessType.UPDATE)
@PutMapping @PutMapping
public AjaxResult edit(@RequestBody ${ClassName} ${className}) { public AjaxResult edit(@Validated @RequestBody ${ClassName} ${className}) {
try { try {
#foreach ($column in $columns)
#if($column.isRequired == 1)
#if($column.javaField.length() > 2 && $column.javaField.substring(1,2).matches("[A-Z]"))
#set($AttrName=$column.javaField)
#else
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
#end
#if($column.javaType.equals("String"))
if (${className}.get${AttrName}() == null || ${className}.get${AttrName}().equals("")) {
#elseif($column.javaType.equals("Integer")||$column.javaType.equals("Long"))
if (${className}.get${AttrName}() == null || ${className}.get${AttrName}()<0) {
#end
return AjaxResult.error("${column.columnComment}不能为空!");
}
#end
#if($column.isRegular != 1)
if (!Pattern.matches("${column.regular}",${className}.get${AttrName}())){
return AjaxResult.error("${column.columnComment}格式错误!");
}
#end
#end
ServerResult<Integer> genServerResult = ${className}Service.update${ClassName}(${className}); ServerResult<Integer> genServerResult = ${className}Service.update${ClassName}(${className});
if (genServerResult.isStart()) { if (genServerResult.isStart()) {
return AjaxResult.success(); return AjaxResult.success();

View File

@ -15,6 +15,8 @@ import ${packageName}.entity.${subClassName};
#end #end
import com.ebts.common.core.entity.${Entity}; import com.ebts.common.core.entity.${Entity};
import com.ebts.common.annotation.Excel; import com.ebts.common.annotation.Excel;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringBuilder;
@ -52,6 +54,12 @@ public class ${ClassName} extends ${Entity}{
#else #else
@Excel(name = "${comment}") @Excel(name = "${comment}")
#end #end
#end
#if($column.isRequired == 1)
@NotNull(message = "${column.columnComment}不能为空!")
#end
#if($column.isRegular != 1)
@Pattern(regexp = "${column.regular}",message = "${column.columnComment}格式错误!")
#end #end
@ApiModelProperty("${column.columnComment}") @ApiModelProperty("${column.columnComment}")
private $column.javaType $column.javaField; private $column.javaType $column.javaField;