我在带有Hibernate的Struts 2中有一个示例应用程序。我开始从Struts 2测试日期选择器,但由于某种原因,即使Java代码将其视为bytea
(因为Struts 2将其作为字符串返回),后来又作为String。 >。
这是在数据库(PostgreSQL)上发生的:
我有一个DTO的LocalDate
类:
public class UserPOJO {
private String name;
private String password;
private String email;
private String cargo;
private String nasc;
然后,在User构造函数上,将其转换为
UserPOJO
:public User(UserPOJO pojo) {
this.name = pojo.getName();
this.password = pojo.getPassword();
this.email = pojo.getEmail();
String s = pojo.getNasc().substring(0,10);
this.nasc = LocalDate.parse(s);
this.cargo = new Cargo();
this.cargo.setId(Integer.parseInt(pojo.getCargo()));
}
当我从数据库中检索数据以在屏幕上显示时,它可以正常工作。但是我不知道为什么将其另存为
LocalDate
以及为什么它可以用于检索数据。我想将其另存为bytea
在数据库上。我正在使用Java 8,Struts 2.3.15.1,Hibernate 4.3.5.Final,PostgreSQL 11和Struts 2 DOJO插件2.3.4.1。
最佳答案
在数据库中,数据类型更改为日期。
检查是否有效。