1 changed files with 64 additions and 0 deletions
@ -0,0 +1,64 @@ |
|||
package com.epmet.controller; |
|||
|
|||
import com.epmet.commons.tools.utils.Result; |
|||
import com.epmet.commons.tools.validator.ValidatorUtils; |
|||
import com.epmet.commons.tools.validator.group.CustomerClientShowGroup; |
|||
import lombok.Data; |
|||
import org.springframework.web.bind.annotation.PostMapping; |
|||
import org.springframework.web.bind.annotation.RequestBody; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
import javax.validation.constraints.NotBlank; |
|||
|
|||
@RestController |
|||
@RequestMapping("demo") |
|||
public class DemoController { |
|||
|
|||
@PostMapping("adduser") |
|||
public Result addUser(@RequestBody UserFormDTO form) { |
|||
ValidatorUtils.validateEntity(form, UserFormDTO.AddUserShowGroup.class, UserFormDTO.AddUserInternalGroup.class); |
|||
System.out.println(form); |
|||
return new Result(); |
|||
} |
|||
|
|||
} |
|||
|
|||
@Data |
|||
class UserFormDTO { |
|||
//>>>>>>>>>>>>>>>>>校验分组开始>>>>>>>>>>>>>>>>>>>>>
|
|||
/** |
|||
* 添加用户操作的内部异常分组 |
|||
* 出现错误会提示给前端7000错误码,返回信息为:服务器开小差... |
|||
*/ |
|||
public interface AddUserInternalGroup {} |
|||
|
|||
/** |
|||
* 添加用户操作的用户可见异常分组 |
|||
* 该分组用于校验需要返回给前端错误信息提示的列,需要继承CustomerClientShowGroup |
|||
* 返回错误码为8999,提示信息为DTO中具体的列的校验注解message的内容 |
|||
*/ |
|||
public interface AddUserShowGroup extends CustomerClientShowGroup {} |
|||
|
|||
// <<<<<<<<<<<<<<<<<<<校验分组结束<<<<<<<<<<<<<<<<<<<<<<<<
|
|||
|
|||
/** |
|||
* 该字段在查询用户和添加用户的时候都要校验,所以在groups中会添加2个分组,校验器会优先校验继承了CustomerClientShowGroup |
|||
* 的分组 |
|||
* 1.该分组校验出错,直接将信息返回客户端,(多个字段有错误,多个字段的错误信息 |
|||
* 拼接起来,逗号分隔,详见ValidatorUtils#validadtorEntity()方法) |
|||
* 2.该分组校验成功,则继续往下,校验内部错误,若出现内部错误,则返回7000,服务器开小差... |
|||
*/ |
|||
@NotBlank(message = "请输入姓名信息", groups = { AddUserInternalGroup.class, AddUserShowGroup.class }) |
|||
private String name; |
|||
|
|||
/** |
|||
* 用户别名,只在内部传输,因此它所属的分组不能继承CustomerClientShowGroup |
|||
*/ |
|||
@NotBlank(message = "用户别名不能为空", groups = { AddUserInternalGroup.class }) |
|||
private String alias; |
|||
|
|||
@NotBlank(message = "请输入地址信息", groups = { AddUserShowGroup.class }) |
|||
private String address; |
|||
|
|||
} |
Loading…
Reference in new issue