SSH里,实体类有日期字段,我设置的是Calendar类型。然后用注解加上注解,如
@Column(name = "fasjsx")
private Calendar caseHpUpLmt;
getter/setter...查询的时候,使用getHibernateTemplate().find(queryString),如:
String queryString = "from CaseInfo";
List list = getHibernateTemplate().find(queryString);
查询出实体后,发现所有的字段变成了java.util.GregorianCalendar类型!将查询结果返回给前台的时候,我的做法如下:JSONObject object = new JSONObject();
object.put("success", true);
object.put("caseInfo", caseInfo);
try{
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("text/html;charset=utf-8");
PrintWriter pw = response.getWriter();
pw.print(object.toString());
pw.close();
}catch (Exception e) {
ret = false;
e.printStackTrace();
}控制台报出:[net.sf.json.JSONObject]-[INFO] Property 'actualMaximum' of class java.util.GregorianCalendar has no read method. SKIPPED
[net.sf.json.JSONObject]-[INFO] Property 'actualMinimum' of class java.util.GregorianCalendar has no read method. SKIPPED
[net.sf.json.JSONObject]-[INFO] Property 'greatestMinimum' of class java.util.GregorianCalendar has no read method. SKIPPED
[net.sf.json.JSONObject]-[INFO] Property 'leastMaximum' of class java.util.GregorianCalendar has no read method. SKIPPED
[net.sf.json.JSONObject]-[INFO] Property 'maximum' of class java.util.GregorianCalendar has no read method. SKIPPED
[net.sf.json.JSONObject]-[INFO] Property 'minimum' of class java.util.GregorianCalendar has no read method. SKIPPED(关于上面的warning,都说java内省机制,缺少getset导致的,但我的实体bean里真有getset呀)最后,前台就显示不了日期字段值了。具体的流程背景就这样了。实体类有Calendar类型的字段,如何做JSON转换?请各位帮帮忙,谢谢咯