ureport2预览sql时间格式化错误
内容目录
ureport2用的是jackson1.x,那时候貌似还没有java8,但是现在的项目都是基于jdk8做的,所以格式化时间的时候,如果是LocalDateTime是格式化有问题的,返回的是对象类型。
我尝试过用jackson2.x的版本,结果格式化xml的时候会报错,然后我就直接换了fastjson,完美解决问题。
1.ureport2-console添加依赖
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.76</version>
</dependency>
2.修改WriteJsonServletAction
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
/**
* @author nelsn
* @since 2021/07/13
*/
public abstract class WriteJsonServletAction extends BaseServletAction {
protected void writeObjectToJson(HttpServletResponse resp, Object obj) throws ServletException, IOException {
resp.setContentType("text/json");
resp.setCharacterEncoding("UTF-8");
OutputStream out = resp.getOutputStream();
try {
//System.out.println("格式化json:"+ JSON.toJSONString(obj));
JSON.writeJSONString(out, obj, SerializerFeature.WriteDateUseDateFormat);
} finally {
out.flush();
out.close();
}
}
}