- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我遇到一个问题,如何验证 json 中的空输入?
这是我的代码:
@RequestMapping(value="/findAdpId/", method=RequestMethod.POST , consumes = "application/json", produces = "application/json")
public @ResponseBody String findAdpId(@RequestBody AllCustomerHist customer){
String customerId = customer.getCustomerId();
String srctable = customer.getSrctable();
String message;
System.out.println("customer ID = "+customerId);
System.out.println("srctable = "+srctable);
// List<AllCustomerHist> adpcust = allCustomerHistService.findAdpId(customerId, srctable);
BigDecimal adpcust = (BigDecimal) allCustomerHistService.findAdpId(customerId, srctable);
JSONObject json = new JSONObject();
json.put("adpId", adpcust);
message = json.toString();
return message;
}
我想要的只是验证 customerId
和 srctable
不为空值,这是我的 dto
@Entity
@Table(name="all_customer_hist")
public class AllCustomerHist {
@Column(name = "REFF_FLAG")
private String reffFlag;
@Column(name = "REFF_ID", precision = 19, scale = 0)
private BigDecimal reffId;
@Column(name = "LAST_UPDATED_DATE")
private Date lastUpdatedDate;
@Column(name = "CREATED_DATE")
private Date createdDate;
@Column(name = "CUSTOMER_ID", length = 255)
private String customerId;
@Column(name = "NAME", length = 255)
private String name;
@Column(name = "DOB", length = 255)
private String dob;
@Column(name = "BIRTH_PLACE", length = 255)
private String birthPlace;
@Column(name = "GENDER", length = 255)
private String gender;
@Column(name = "RELIGION", length = 255)
private String religion;
@Column(name = "EDUCATION", length = 255)
private String education;
@Column(name = "EMPLOYEE_TYPE", length = 255)
private String employeeType;
@Column(name = "MARITAL_STATUS", length = 255)
private String maritalStatus;
@Column(name = "ADDRESS", length = 300)
private String address;
@Column(name = "CITY", length = 255)
private String city;
@Column(name = "KECAMATAN", length = 255)
private String kecamatan;
@Column(name = "KELURAHAN", length = 255)
private String kelurahan;
@Column(name = "ZIP_CODE", length = 255)
private String zipCode;
@Column(name = "BPS_CODE", length = 255)
private String bpsCode;
@Column(name = "ID_TYPE", length = 255)
private String idType;
@Column(name = "ID_NUMBER", length = 255)
private String idNumber;
@Column(name = "NPWP", length = 255)
private String npwp;
@Column(name = "HOME_PHONE_1", length = 255)
private String homePhone1;
@Column(name = "HOME_PHONE_2", length = 255)
private String homePhone2;
@Column(name = "HOME_PHONE_3", length = 255)
private String homePhone3;
@Column(name = "HOME_PHONE_4", length = 255)
private String homePhone4;
@Column(name = "HOME_PHONE_5", length = 255)
private String homePhone5;
@Column(name = "OFFICE_PHONE_1", length = 255)
private String officePhone1;
@Column(name = "OFFICE_PHONE_2", length = 255)
private String officePhone2;
@Column(name = "OFFICE_PHONE_3", length = 255)
private String officePhone3;
@Column(name = "OFFICE_PHONE_4", length = 255)
private String officePhone4;
@Column(name = "OFFICE_PHONE_5", length = 255)
private String officePhone5;
@Column(name = "MOBILE_PHONE_1", length = 255)
private String mobilePhone1;
@Column(name = "MOBILE_PHONE_2", length = 255)
private String mobilePhone2;
@Column(name = "MOBILE_PHONE_3", length = 255)
private String mobilePhone3;
@Column(name = "MOBILE_PHONE_4", length = 255)
private String mobilePhone4;
@Column(name = "MOBILE_PHONE_5", length = 255)
private String mobilePhone5;
@Column(name = "FAX_NUMBER_1", length = 255)
private String faxNumber1;
@Column(name = "FAX_NUMBER_2", length = 255)
private String faxNumber2;
@Column(name = "EMAIL_1", length = 255)
private String email1;
@Column(name = "EMAIL_2", length = 255)
private String email2;
@Column(name = "EMAIL_3", length = 255)
private String email3;
@Column(name = "SRCTABLE", length = 255)
private String srctable;
@Column(name = "ADP_ID", precision = 19, scale = 0)
private BigDecimal adpId;
@Id
@GeneratedValue(strategy=GenerationType.AUTO, generator="my_entity_seq_gen")
@SequenceGenerator(name="my_entity_seq_gen", sequenceName="SYSTEMID")
@Column(name = "SYSTEM_ID", precision = 19, scale = 0)
private BigDecimal systemId;
//Release 1.2
@Column(name = "NAME_RAW", length = 255)
private String nameRaw;
@Column(name = "CUSTOMER_TITLE", length = 8)
private String customerTitle;
@Column(name = "GENDERTITLE", length = 8)
private String gendertitle;
public String getNameRaw() {
return nameRaw;
}
public void setNameRaw(String nameRaw) {
this.nameRaw = nameRaw;
}
public String getCustomerTitle() {
return customerTitle;
}
public void setCustomerTitle(String customerTitle) {
this.customerTitle = customerTitle;
}
public String getGendertitle() {
return gendertitle;
}
public void setGendertitle(String gendertitle) {
this.gendertitle = gendertitle;
}
public String getReffFlag() {
return reffFlag;
}
public void setReffFlag(String reffFlag) {
this.reffFlag = reffFlag;
}
public BigDecimal getReffId() {
return reffId;
}
public void setReffId(BigDecimal reffId) {
this.reffId = reffId;
}
public Date getLastUpdatedDate() {
return lastUpdatedDate;
}
public void setLastUpdatedDate(Date lastUpdatedDate) {
this.lastUpdatedDate = lastUpdatedDate;
}
public Date getCreatedDate() {
return createdDate;
}
public void setCreatedDate(Date createdDate) {
this.createdDate = createdDate;
}
public String getCustomerId() {
return customerId;
}
public void setCustomerId(String customerId) {
this.customerId = customerId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDob() {
return dob;
}
public void setDob(String dob) {
this.dob = dob;
}
public String getBirthPlace() {
return birthPlace;
}
public void setBirthPlace(String birthPlace) {
this.birthPlace = birthPlace;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getReligion() {
return religion;
}
public void setReligion(String religion) {
this.religion = religion;
}
public String getEducation() {
return education;
}
public void setEducation(String education) {
this.education = education;
}
public String getEmployeeType() {
return employeeType;
}
public void setEmployeeType(String employeeType) {
this.employeeType = employeeType;
}
public String getMaritalStatus() {
return maritalStatus;
}
public void setMaritalStatus(String maritalStatus) {
this.maritalStatus = maritalStatus;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getKecamatan() {
return kecamatan;
}
public void setKecamatan(String kecamatan) {
this.kecamatan = kecamatan;
}
public String getKelurahan() {
return kelurahan;
}
public void setKelurahan(String kelurahan) {
this.kelurahan = kelurahan;
}
public String getZipCode() {
return zipCode;
}
public void setZipCode(String zipCode) {
this.zipCode = zipCode;
}
public String getBpsCode() {
return bpsCode;
}
public void setBpsCode(String bpsCode) {
this.bpsCode = bpsCode;
}
public String getIdType() {
return idType;
}
public void setIdType(String idType) {
this.idType = idType;
}
public String getIdNumber() {
return idNumber;
}
public void setIdNumber(String idNumber) {
this.idNumber = idNumber;
}
public String getNpwp() {
return npwp;
}
public void setNpwp(String npwp) {
this.npwp = npwp;
}
public String getHomePhone1() {
return homePhone1;
}
public void setHomePhone1(String homePhone1) {
this.homePhone1 = homePhone1;
}
public String getHomePhone2() {
return homePhone2;
}
public void setHomePhone2(String homePhone2) {
this.homePhone2 = homePhone2;
}
public String getHomePhone3() {
return homePhone3;
}
public void setHomePhone3(String homePhone3) {
this.homePhone3 = homePhone3;
}
public String getHomePhone4() {
return homePhone4;
}
public void setHomePhone4(String homePhone4) {
this.homePhone4 = homePhone4;
}
public String getHomePhone5() {
return homePhone5;
}
public void setHomePhone5(String homePhone5) {
this.homePhone5 = homePhone5;
}
public String getOfficePhone1() {
return officePhone1;
}
public void setOfficePhone1(String officePhone1) {
this.officePhone1 = officePhone1;
}
public String getOfficePhone2() {
return officePhone2;
}
public void setOfficePhone2(String officePhone2) {
this.officePhone2 = officePhone2;
}
public String getOfficePhone3() {
return officePhone3;
}
public void setOfficePhone3(String officePhone3) {
this.officePhone3 = officePhone3;
}
public String getOfficePhone4() {
return officePhone4;
}
public void setOfficePhone4(String officePhone4) {
this.officePhone4 = officePhone4;
}
public String getOfficePhone5() {
return officePhone5;
}
public void setOfficePhone5(String officePhone5) {
this.officePhone5 = officePhone5;
}
public String getMobilePhone1() {
return mobilePhone1;
}
public void setMobilePhone1(String mobilePhone1) {
this.mobilePhone1 = mobilePhone1;
}
public String getMobilePhone2() {
return mobilePhone2;
}
public void setMobilePhone2(String mobilePhone2) {
this.mobilePhone2 = mobilePhone2;
}
public String getMobilePhone3() {
return mobilePhone3;
}
public void setMobilePhone3(String mobilePhone3) {
this.mobilePhone3 = mobilePhone3;
}
public String getMobilePhone4() {
return mobilePhone4;
}
public void setMobilePhone4(String mobilePhone4) {
this.mobilePhone4 = mobilePhone4;
}
public String getMobilePhone5() {
return mobilePhone5;
}
public void setMobilePhone5(String mobilePhone5) {
this.mobilePhone5 = mobilePhone5;
}
public String getFaxNumber1() {
return faxNumber1;
}
public void setFaxNumber1(String faxNumber1) {
this.faxNumber1 = faxNumber1;
}
public String getFaxNumber2() {
return faxNumber2;
}
public void setFaxNumber2(String faxNumber2) {
this.faxNumber2 = faxNumber2;
}
public String getEmail1() {
return email1;
}
public void setEmail1(String email1) {
this.email1 = email1;
}
public String getEmail2() {
return email2;
}
public void setEmail2(String email2) {
this.email2 = email2;
}
public String getEmail3() {
return email3;
}
public void setEmail3(String email3) {
this.email3 = email3;
}
public String getSrctable() {
return srctable;
}
public void setSrctable(String srctable) {
this.srctable = srctable;
}
public BigDecimal getAdpId() {
return adpId;
}
public void setAdpId(BigDecimal adpId) {
this.adpId = adpId;
}
public BigDecimal getSystemId() {
return systemId;
}
public void setSystemId(BigDecimal systemId) {
this.systemId = systemId;
}
public AllCustomerHist(){}
public AllCustomerHist(String reffFlag, BigDecimal reffId, Date lastUpdatedDate, Date createdDate,
String customerId, String name, String dob, String birthPlace, String gender, String religion,
String education, String employeeType, String maritalStatus, String address, String city, String kecamatan,
String kelurahan, String zipCode, String bpsCode, String idType, String idNumber, String npwp,
String homePhone1, String homePhone2, String homePhone3, String homePhone4, String homePhone5,
String officePhone1, String officePhone2, String officePhone3, String officePhone4, String officePhone5,
String mobilePhone1, String mobilePhone2, String mobilePhone3, String mobilePhone4, String mobilePhone5,
String faxNumber1, String faxNumber2, String email1, String email2, String email3, String srctable,
BigDecimal adpId, BigDecimal systemId, String nameRaw, String customerTitle, String gendertitle) {
super();
this.reffFlag = reffFlag;
this.reffId = reffId;
this.lastUpdatedDate = lastUpdatedDate;
this.createdDate = createdDate;
this.customerId = customerId;
this.name = name;
this.dob = dob;
this.birthPlace = birthPlace;
this.gender = gender;
this.religion = religion;
this.education = education;
this.employeeType = employeeType;
this.maritalStatus = maritalStatus;
this.address = address;
this.city = city;
this.kecamatan = kecamatan;
this.kelurahan = kelurahan;
this.zipCode = zipCode;
this.bpsCode = bpsCode;
this.idType = idType;
this.idNumber = idNumber;
this.npwp = npwp;
this.homePhone1 = homePhone1;
this.homePhone2 = homePhone2;
this.homePhone3 = homePhone3;
this.homePhone4 = homePhone4;
this.homePhone5 = homePhone5;
this.officePhone1 = officePhone1;
this.officePhone2 = officePhone2;
this.officePhone3 = officePhone3;
this.officePhone4 = officePhone4;
this.officePhone5 = officePhone5;
this.mobilePhone1 = mobilePhone1;
this.mobilePhone2 = mobilePhone2;
this.mobilePhone3 = mobilePhone3;
this.mobilePhone4 = mobilePhone4;
this.mobilePhone5 = mobilePhone5;
this.faxNumber1 = faxNumber1;
this.faxNumber2 = faxNumber2;
this.email1 = email1;
this.email2 = email2;
this.email3 = email3;
this.srctable = srctable;
this.adpId = adpId;
this.systemId = systemId;
this.nameRaw = nameRaw;
this.customerTitle = customerTitle;
this.gendertitle = gendertitle;
}
}
我的目标是,当抛出这个 json 时:
{
"srctable":null,
"customerId":null
}
它应该返回消息,通知消费者 srctable 和 customerId 不能为 null,但我不想在我的 dto 中添加 @NotNull,因为 customerId 和 srctable 对于其他进程可能为 null。
谢谢您,等待您的帮助:D
最佳答案
是时候介绍DTO(数据传输对象)并在 Controller 中使用它了。我猜你不需要某些字段,例如搜索逻辑中不使用实体的lastUpdatedDate。
您需要添加具有必要字段的自定义 POJO,并使用 @NotNull 和所有其他必要的验证检查对其进行注释。必要时您可能还需要一个转换器来将 DTO 转换为实体。
关于java - Spring Restful Web 服务验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45974889/
我尝试阅读有关 Spring BOM、Spring Boot 和 Spring IO 的文档。 但是没有说明,我们应该如何一起使用它们? 在我的项目中,我们已经有了自己的 Parent POM ,所以
我正在开发的很酷的企业应用程序正在转向 Spring。这对所有团队来说都是非常酷和令人兴奋的练习,但也是一个巨大的压力源。我们所做的是逐渐将遗留组件移至 Spring 上下文。现在我们有一个 huuu
我正在尝试使用 @Scheduled 运行 Spring 批处理作业注释如下: @Scheduled(cron = "* * * * * ?") public void launchMessageDi
我对这两个概念有点困惑。阅读 Spring 文档,我发现,例如。 bean 工厂是 Spring 容器。我还读到“ApplicationContext 是 BeanFactory 的完整超集”。但两者
我们有一个使用 Spring BlazeDS 集成的应用程序。到目前为止,我们一直在使用 Spring 和 Flex,它运行良好。我们现在还需要添加一些 Spring MVC Controller 。
假设我有一个类(class) Person带属性name和 age ,它可以像这样用 Spring 配置: 我想要一个自定义的 Spring 模式元素,这很容易做到,允许我在我的 Sp
如何在 Java 中以编程方式使用 Spring Data 创建 MongoDB 复合索引? 使用 MongoTemplate 我可以创建一个这样的索引:mongoTemplate.indexOps(
我想使用 spring-complex-task 执行我的应用程序,并且我已经构建了复杂的 spring-batch Flow Jobs,它执行得非常好。 你能解释一下spring批处理流作业与spr
我实现了 spring-boot 应用程序,现在我想将它用作非 spring 应用程序的库。 如何初始化 lib 类,以便 Autowiring 的依赖项按预期工作?显然,如果我使用“new”创建类实
我刚开始学习 spring cloud security,我有一个基本问题。它与 Spring Security 有何不同?我们是否需要在 spring boot 上构建我们的应用程序才能使用 spr
有很多人建议我使用 Spring Boot 而不是 Spring 来开发 REST Web 服务。我想知道这两者到底有什么区别? 最佳答案 总之 Spring Boot 减少了编写大量配置和样板代码的
您能向我解释一下如何使用 Spring 正确构建 Web 应用程序吗?我知道 Spring 框架的最新版本是 4.0.0.RELEASE,但是 Spring Security 的最新版本是 3.2.0
我如何才能知道作为 Spring Boot 应用程序的一部分加载的所有 bean 的名称?我想在 main 方法中有一些代码来打印服务器启动后加载的 bean 的详细信息。 最佳答案 如spring-
我有一个使用 Spring 3.1 构建的 RESTful API,也使用 Spring Security。我有一个 Web 应用程序,也是一个 Spring 3.1 MVC 应用程序。我计划让移动客
升级到 Spring 5 后,我在 Spring Rabbit 和 Spring AMQP 中遇到错误。 两者现在都设置为 1.5.6.RELEASE 有谁知道哪些版本应该与 Spring 5 兼容?
我现在已经使用 Spring Framework 3.0.5 和 Spring Security 3.0.5 多次了。我知道Spring框架使用DI和AOP。我还知道 Spring Security
我收到错误 Unable to Location NamespaceHandler when using context:annotation-config running (java -jar) 由
在 Spring 应用程序中嵌入唯一版本号的策略是什么? 我有一个使用 Spring Boot 和 Spring Web 的应用程序。 它已经足够成熟,我想对其进行版本控制并在运行时看到它显示在屏幕上
我正在使用 spring data jpa 进行持久化。如果存在多个具有相同名称的实体,是否有一种方法可以将一个实体标记为默认值。类似@Primary注解的东西用来解决多个bean的依赖问题 @Ent
我阅读了 Spring 框架的 DAOSupport 类。但是我无法理解这些 DAOSuport 类的优点。在 DAOSupport 类中,我们调用 getXXXTemplate() 方法来获取特定的
我是一名优秀的程序员,十分优秀!