This commit is contained in:
parent
b10200e2af
commit
8bdf414948
|
|
@ -101,7 +101,7 @@ public class ${ClassName}Controller extends HcyBaseController {
|
||||||
@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}) {
|
||||||
try {
|
try {
|
||||||
ServerResult<Stu> serverResult = ${className}Service.select${ClassName}ById(${pkColumn.javaField});
|
ServerResult<${ClassName}> serverResult = ${className}Service.select${ClassName}ById(${pkColumn.javaField});
|
||||||
if (serverResult.isStart()) {
|
if (serverResult.isStart()) {
|
||||||
return AjaxResult.success(serverResult.getData());
|
return AjaxResult.success(serverResult.getData());
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -120,6 +120,22 @@ public class ${ClassName}Controller extends HcyBaseController {
|
||||||
@Log(title = "${functionName}", businessType = BusinessType.INSERT)
|
@Log(title = "${functionName}", businessType = BusinessType.INSERT)
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public AjaxResult add(@RequestBody ${ClassName} ${className}) {
|
public AjaxResult add(@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
|
||||||
|
#end
|
||||||
try {
|
try {
|
||||||
ServerResult<Integer> serverResult = ${className}Service.insert${ClassName}(${className});
|
ServerResult<Integer> serverResult = ${className}Service.insert${ClassName}(${className});
|
||||||
if (serverResult.isStart()) {
|
if (serverResult.isStart()) {
|
||||||
|
|
@ -141,6 +157,23 @@ public class ${ClassName}Controller extends HcyBaseController {
|
||||||
@PutMapping
|
@PutMapping
|
||||||
public AjaxResult edit(@RequestBody ${ClassName} ${className}) {
|
public AjaxResult edit(@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
|
||||||
|
#end
|
||||||
ServerResult<Integer> serverResult = ${className}Service.update${ClassName}(${className});
|
ServerResult<Integer> serverResult = ${className}Service.update${ClassName}(${className});
|
||||||
if (serverResult.isStart()) {
|
if (serverResult.isStart()) {
|
||||||
return AjaxResult.success();
|
return AjaxResult.success();
|
||||||
|
|
|
||||||
|
|
@ -164,7 +164,7 @@ public class ${ClassName}ServiceImpl implements ${ClassName}Service {
|
||||||
@Transactional
|
@Transactional
|
||||||
#end
|
#end
|
||||||
@Override
|
@Override
|
||||||
public int delete${ClassName}ByIds(${pkColumn.javaType}[] ${pkColumn.javaField}s) {
|
public ServerResult<Integer> delete${ClassName}ByIds(${pkColumn.javaType}[] ${pkColumn.javaField}s) {
|
||||||
try {
|
try {
|
||||||
#if($table.sub)
|
#if($table.sub)
|
||||||
${className}Dao.delete${subClassName}By${subTableFkClassName}s(${pkColumn.javaField}s);
|
${className}Dao.delete${subClassName}By${subTableFkClassName}s(${pkColumn.javaField}s);
|
||||||
|
|
@ -188,7 +188,7 @@ public class ${ClassName}ServiceImpl implements ${ClassName}Service {
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int delete${ClassName}ById(${pkColumn.javaType} ${pkColumn.javaField}) {
|
public ServerResult<Integer> delete${ClassName}ById(${pkColumn.javaType} ${pkColumn.javaField}) {
|
||||||
try {
|
try {
|
||||||
#if($table.sub)
|
#if($table.sub)
|
||||||
${className}Dao.delete${subClassName}By${subTableFkClassName}(${pkColumn.javaField});
|
${className}Dao.delete${subClassName}By${subTableFkClassName}(${pkColumn.javaField});
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package com.hchyun.test.controller;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
|
||||||
import com.hchyun.common.constant.ReturnConstants;
|
import com.hchyun.common.constant.ReturnConstants;
|
||||||
|
|
@ -25,6 +26,7 @@ import com.hchyun.common.enums.BusinessType;
|
||||||
import com.hchyun.test.entity.Stu;
|
import com.hchyun.test.entity.Stu;
|
||||||
import com.hchyun.test.service.StuService;
|
import com.hchyun.test.service.StuService;
|
||||||
import com.hchyun.common.utils.poi.ExcelUtil;
|
import com.hchyun.common.utils.poi.ExcelUtil;
|
||||||
|
import com.hchyun.common.core.page.TableDataInfo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 学生Controller
|
* 学生Controller
|
||||||
|
|
@ -107,6 +109,15 @@ public class StuController extends HcyBaseController {
|
||||||
@Log(title = "学生", businessType = BusinessType.INSERT)
|
@Log(title = "学生", businessType = BusinessType.INSERT)
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public AjaxResult add(@RequestBody Stu stu) {
|
public AjaxResult add(@RequestBody Stu stu) {
|
||||||
|
if (stu.getName() == null || stu.getName().equals("")) {
|
||||||
|
return AjaxResult.error("学生姓名不能为空!");
|
||||||
|
}
|
||||||
|
if (stu.getTel() == null || stu.getTel()<0) {
|
||||||
|
return AjaxResult.error("电话不能为空!");
|
||||||
|
}
|
||||||
|
if (stu.getEmail() == null || stu.getEmail().equals("")) {
|
||||||
|
return AjaxResult.error("电子邮件不能为空!");
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
ServerResult<Integer> serverResult = stuService.insertStu(stu);
|
ServerResult<Integer> serverResult = stuService.insertStu(stu);
|
||||||
if (serverResult.isStart()) {
|
if (serverResult.isStart()) {
|
||||||
|
|
@ -128,6 +139,16 @@ public class StuController extends HcyBaseController {
|
||||||
@PutMapping
|
@PutMapping
|
||||||
public AjaxResult edit(@RequestBody Stu stu) {
|
public AjaxResult edit(@RequestBody Stu stu) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
if (stu.getName() == null || stu.getName().equals("")) {
|
||||||
|
return AjaxResult.error("学生姓名不能为空!");
|
||||||
|
}
|
||||||
|
if (stu.getTel() == null || stu.getTel()<0) {
|
||||||
|
return AjaxResult.error("电话不能为空!");
|
||||||
|
}
|
||||||
|
if (stu.getEmail() == null || stu.getEmail().equals("")) {
|
||||||
|
return AjaxResult.error("电子邮件不能为空!");
|
||||||
|
}
|
||||||
ServerResult<Integer> serverResult = stuService.updateStu(stu);
|
ServerResult<Integer> serverResult = stuService.updateStu(stu);
|
||||||
if (serverResult.isStart()) {
|
if (serverResult.isStart()) {
|
||||||
return AjaxResult.success();
|
return AjaxResult.success();
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ public class Stu extends BaseEntity
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
|
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||||
.append("id", getId())
|
.append("id", getId())
|
||||||
.append("name", getName())
|
.append("name", getName())
|
||||||
.append("tel", getTel())
|
.append("tel", getTel())
|
||||||
|
|
|
||||||
|
|
@ -34,15 +34,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
<insert id="insertStu" parameterType="Stu" useGeneratedKeys="true" keyProperty="id">
|
<insert id="insertStu" parameterType="Stu" useGeneratedKeys="true" keyProperty="id">
|
||||||
insert into sys_stu
|
insert into sys_stu
|
||||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||||
<if test="name != null">name,</if>
|
<if test="name != null and name != ''">name,</if>
|
||||||
<if test="tel != null">tel,</if>
|
<if test="tel != null">tel,</if>
|
||||||
<if test="email != null">email,</if>
|
<if test="email != null and email != ''">email,</if>
|
||||||
<if test="createTime != null">create_time,</if>
|
<if test="createTime != null">create_time,</if>
|
||||||
</trim>
|
</trim>
|
||||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||||
<if test="name != null">#{name},</if>
|
<if test="name != null and name != ''">#{name},</if>
|
||||||
<if test="tel != null">#{tel},</if>
|
<if test="tel != null">#{tel},</if>
|
||||||
<if test="email != null">#{email},</if>
|
<if test="email != null and email != ''">#{email},</if>
|
||||||
<if test="createTime != null">#{createTime},</if>
|
<if test="createTime != null">#{createTime},</if>
|
||||||
</trim>
|
</trim>
|
||||||
</insert>
|
</insert>
|
||||||
|
|
@ -50,9 +50,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
<update id="updateStu" parameterType="Stu">
|
<update id="updateStu" parameterType="Stu">
|
||||||
update sys_stu
|
update sys_stu
|
||||||
<trim prefix="SET" suffixOverrides=",">
|
<trim prefix="SET" suffixOverrides=",">
|
||||||
<if test="name != null">name = #{name},</if>
|
<if test="name != null and name != ''">name = #{name},</if>
|
||||||
<if test="tel != null">tel = #{tel},</if>
|
<if test="tel != null">tel = #{tel},</if>
|
||||||
<if test="email != null">email = #{email},</if>
|
<if test="email != null and email != ''">email = #{email},</if>
|
||||||
<if test="createTime != null">create_time = #{createTime},</if>
|
<if test="createTime != null">create_time = #{createTime},</if>
|
||||||
</trim>
|
</trim>
|
||||||
where id = #{id}
|
where id = #{id}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue