From 4e07218f703520edbd157e9afe2e5636b12270dd Mon Sep 17 00:00:00 2001 From: wxz Date: Mon, 1 Jun 2020 10:11:48 +0800 Subject: [PATCH] =?UTF-8?q?1.=E5=88=86=E7=BB=84=E6=A0=A1=E9=AA=8Cdemo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/epmet/controller/DemoController.java | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/controller/DemoController.java diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/controller/DemoController.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/controller/DemoController.java new file mode 100644 index 0000000000..357ea2c9af --- /dev/null +++ b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/controller/DemoController.java @@ -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; + +} \ No newline at end of file