|
@@ -0,0 +1,64 @@
|
|
|
+package com.zhentao.controller;
|
|
|
+
|
|
|
+import com.zhentao.pojo.Object1;
|
|
|
+import jakarta.validation.ConstraintViolation;
|
|
|
+import jakarta.validation.Validation;
|
|
|
+import jakarta.validation.Validator;
|
|
|
+import jakarta.validation.ValidatorFactory;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestHeader;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.Set;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("api")
|
|
|
+public class ApiController {
|
|
|
+ @RequestMapping("/find1")
|
|
|
+ public Object1 find1(@RequestBody Object1 object1,@RequestHeader("reqId") String reqId){
|
|
|
+
|
|
|
+ ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
|
|
|
+ Validator validator = factory.getValidator();
|
|
|
+ Set<ConstraintViolation<Object1>> violations = validator.validate(object1);
|
|
|
+
|
|
|
+ if (violations.isEmpty()) {
|
|
|
+ System.out.println("邮箱地址验证通过");
|
|
|
+
|
|
|
+ return object1;
|
|
|
+ } else {
|
|
|
+ for (ConstraintViolation<Object1> violation : violations) {
|
|
|
+ System.out.println(violation.getMessage());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ @RequestMapping("/find2")
|
|
|
+ public Object1 find2(String appId,
|
|
|
+ Integer goodsId,
|
|
|
+ BigDecimal price,
|
|
|
+ String mobile,@RequestHeader("reqId") String reqId){
|
|
|
+ Object1 object1=new Object1();
|
|
|
+ object1.setAppId(appId);
|
|
|
+ object1.setGoodsId(goodsId);
|
|
|
+ object1.setPrice(price);
|
|
|
+ object1.setMobile(mobile);
|
|
|
+ System.err.println(reqId);
|
|
|
+ ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
|
|
|
+ Validator validator = factory.getValidator();
|
|
|
+ Set<ConstraintViolation<Object1>> violations = validator.validate(object1);
|
|
|
+ if (violations.isEmpty()) {
|
|
|
+ System.out.println("邮箱地址验证通过");
|
|
|
+
|
|
|
+ return object1;
|
|
|
+ } else {
|
|
|
+ for (ConstraintViolation<Object1> violation : violations) {
|
|
|
+ System.out.println(violation.getMessage());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|