zoukankan      html  css  js  c++  java
  • Spring2.5 MVC 2.5.6 传JSON对象

    网上大部分是spring3.0的传JSON对象,spring3自带了支持JSON对象。

    关于spring2.5,也很简单。导入两个jackson的jar包,然后手动传json对象

    Java代码 复制代码 收藏代码
    1. jackson-core-asl-1.9.11.jar
    2. jackson-mapper-asl-1.9.11.jar

    原来controller里面传ModelAndView:

    Java代码 复制代码 收藏代码
    1. public ModelAndView test(HttpServletRequest req, HttpServletResponse res)
    2. throws Exception {
    3. return new ModelAndView(view, model);
    4. }

    改成传json对象

    Java代码 复制代码 收藏代码
    1. public ModelAndView test(HttpServletRequest req, HttpServletResponse res)
    2. throws Exception {
    3. ObjectMapper mapper = new ObjectMapper();
    4. res.getOutputStream().print(mapper.writeValueAsString(dinnerList));
    5. res.getOutputStream().flush();
    6. res.getOutputStream().close();
    7. // res.getOutputStream().write(new String("No parameter found.").getBytes());
    8. return null;
    9. }

  • 相关阅读:
    Vue3.0
    Vue
    Vue
    Vue3.0
    Vue
    Vue
    Vue
    Vue
    Vue3.0
    万字长文|十大基本排序,一次搞定!
  • 原文地址:https://www.cnblogs.com/bjanzhuo/p/3576102.html
Copyright © 2011-2022 走看看