Java 验证请求数据完整性信息
来源:互联网 发布:凯利指数软件 编辑:程序博客网 时间:2024/06/06 20:57
CreditAntifraudReq 请求接收实体类
package com.frms.exchange.command;import lombok.Getter;import lombok.NoArgsConstructor;import lombok.Setter;import org.hibernate.validator.constraints.NotEmpty;import java.io.Serializable;@Getter@Setter@NoArgsConstructor/** * 请求参数 */public class CreditAntifraudReq implements Serializable{ @NotEmpty(message = "用户ID不能为空") private String userId; @NotEmpty(message = "欺诈产品类别不能为空") private String productType; @NotEmpty(message = "姓名不能为空") private String name; @NotEmpty(message = "身份证号不能为空") private String certNo; private String mobile; private String email; }
CreditAntifraudController 前端调用方法实现类
import javax.validation.ConstraintViolation;import javax.validation.Validator;import java.net.URLDecoder;import java.util.Set;import lombok.extern.slf4j.Slf4j;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestBody;import org.springframework.web.bind.annotation.RequestMapping;@Slf4j@Controller@RequestMapping("creditAntifraud")public class CreditAntifraudController { @Override public CreditAntifraudRes getCreditAntifraud(@RequestBody CreditAntifraudReq CreditAntifraudReq){ //调用验证方法 CreditAntifraudRes res = validtateRequest(CreditAntifraudReq); if(res == null){ res = aliPayService.getCreditAntifraud(CreditAntifraudReq); } return res; } /** * 验证请求数据完整性信息 * * @param req */ private CreditAntifraudRes validtateRequest(CreditAntifraudReq req) { Set<ConstraintViolation<CreditAntifraudReq>> violations = validator.validate(req); StringBuilder sb = new StringBuilder(); for (ConstraintViolation<CreditAntifraudReq> violation : violations) { sb.append(violation.getMessage()).append(";"); } CreditAntifraudRes res = null; //如果大于0则有数据为空 if (sb.length() > 0) { res = new CreditAntifraudRes(); res.setErrorCode("1000"); res.setErrorMessage(sb.toString()); } return res; }}
阅读全文
0 0
- Java 验证请求数据完整性信息
- JAVA中进行数据完整性验证
- 云存储数据的一般完整性验证
- 利用.sig文件验证数据的完整性
- Java 保证数据的完整性
- 验证html片段完整性(java代码)
- 信息完整性
- 信息完整性
- java异常信息完整性的控制
- java异常信息完整性的控制
- 数据完整性
- 数据完整性
- 数据完整性
- 数据完整性
- 数据完整性
- java中使用MD5验证文件的完整性
- Java验证身份证信息
- 验证下载文件完整性
- Jdk7u21 反序列化漏洞Gadget原理
- mongoDB修改数据
- 利用AOP加注解的形式完成代码的优化
- AngularJS 动态添加展示数据
- 快速排序
- Java 验证请求数据完整性信息
- 乱码问题详解2
- scikit-learn 中文文档-交叉分解-监督学习|ApacheCN
- linux shell 字符串操作(长度,查找,替换)详解BASH
- 月度总结
- 二进制按位逻辑运算符2017/11/22
- 小马哥Linux笔记
- H
- mvp+Retrofit+rxj+greendao的数据请求和增查