AngularJS处理ASP.Net MVC Json返回日期

ASP.NET MVC 在返回 JSON 类型时,,时间的格式会是 "/Date(1306418993027)/"


public ActionResult Test(){    List<Person> persons = new List<Person>();    //...    return Json(persons, JsonRequestBehavior.AllowGet);}
其中Person有birthday字段(DateTime)。


返回的json中,日期格式时间的格式会是 "/Date(1306418993027)/"。


js中可以用


return new Date(parseInt(x.substr(6)));
来处理。


在AngularJS中,只要自定义filter即可。


myApp.filter("jsDate", function () {    return function (x) {        if (null == x) {            return null;        }        else {            return new Date(parseInt(x.substr(6)));        }    };});
在使用的地方


<td>{{person.birthday|jsDate| date: 'yyyy-MM-dd HH:mm:ss'}}</td>
其中date是AngularJS自带的过滤器。


发布了99 篇原创文章 · 获赞 68 · 访问量 53万+
展开阅读全文

Spring MVC + Spring + Mybatis + JqGrid 前台数据显示不出来

07-21

json ``` @Controller @RequestMapping("/crud") public class UserController { @Resource(name="userServiceImpl") private UserService userService; @RequestMapping(method = RequestMethod.GET) public @ResponseBody CustomUserResponse findAllUser(){ List<UserVO> users = userService.getAllUsers(); CustomUserResponse response = new CustomUserResponse(); response.setRows(users); response.setRecords( String.valueOf(users.size()) ); response.setPage( "1" ); response.setTotal( "10" ); return response;//返回给jqGrid } } ``` jsp ``` <script type ="text/javascript"> $(function () { $("#list").jqGrid({ url: "/GridApp/crud",//获取数据的地址 datatype: "json",//从服务器端返回的数据类型,默认xml mtype: "GET",//ajax提交方式。POST或者GET,默认GET colNames: ["编号", "姓名", "性别", "年龄", "备注"],//列显示名称,是一个数组对象 /* 常用到的属性:name 列显示的名称;index 传到服务器端用来排序用的列名称; width 列宽度;align 对齐方式;sortable 是否可以排序 */ colModel: [ { name: "id", width: 55 }, { name: "name", width: 90 }, { name: "sex", width: 80, align: "right" }, { name: "age", width: 80, align: "right" }, { name: "remark", width: 80, align: "right" } ], pager: "#pager", //定义翻页用的导航栏,必须是有效的html元素。翻页工具栏可以放置在html页面任意位置 rowNum: 10, //在grid上显示记录条数,这个参数是要被传递到后台 rowList: [10, 20, 30],//一个下拉选择框,用来改变显示记录数,当选择时会覆盖rowNum参数传递到后台 sortname: "invid",//默认的排序列。可以是列名称或者是一个数字,这个参数会被提交到后台 sortorder: "desc",//排序顺序,升序或者降序(asc or desc) viewrecords: true,//定义是否要显示总记录数 emptyrecords: "Empty records",//当返回的数据行数为0时显示的信息。只有当属性 viewrecords 设置为ture时起作用 gridview: true,//构造一行数据后添加到grid中,如果设为true则是将整个表格的数据都构造完成后再添加到grid中,但treeGrid, subGrid, or afterInsertRow 不能用 autoencode: true,//对url进行编码 caption: "My first grid",//表格名称 jsonReader : { root: "rows", page: "page", total: "total", records: "records", repeatitems: false, cell: "cell", id: "id" } }); }); </script> <body> <table id = "list" ><tr><td></td></tr></table> <div id = "pager"></div> </body> ``` 异常 严重: Servlet.service() for servlet [springmvc] in context with path [/GridApp] threw exception [Request processing failed; nested exception is java.lang.IllegalArgumentException: No converter found for return value of type: class com.java.json.CustomUserResponse] with root cause java.lang.IllegalArgumentException: No converter found for return value of type: class com.java.json.CustomUserResponse at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:178) at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:153) at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.handleReturnValue(RequestResponseBodyMethodProcessor.java:165) at org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:80) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:126) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:814) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:737) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) at javax.servlet.http.HttpServlet.service(HttpServlet.java:624) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) at javax.servlet.http.HttpServlet.service(HttpServlet.java:731) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:442) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1082) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:623) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745) 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览