码迷,mamicode.com
首页 > 其他好文 > 详细

NoSession问题

时间:2017-08-17 18:29:45      阅读:112      评论:0      收藏:0      [点我收藏+]

标签:技术   ext   from   排除   images   spring   port   初始化   关闭   

第一种原因:

 no Session 错误
 dao层中get方法换成了load方法,或者其他原因引起.
 原因分析: 真正用到代理对象的时候,代理对象没有值,并且session的生命周期已经走完了.
 解决方案:1,load()换成get(),或者立即查询,比如打印一下.
      2,延长session的存活时间,---- OpenSessionInViewFilter
web.xml中配置:
  <!-- 延长session存活时间 -->
  <filter>
      <filter-name>OpenSession</filter-name>
      <filter-class>org.springframework.orm.hibernate5.support.OpenSessionInViewFilter</filter-class>
  </filter>
  <filter-mapping>
      <filter-name>OpenSession</filter-name>
      <url-pattern>/*</url-pattern>
  </filter-mapping>
 技术分享

 

第二种原因:

NoSession
  初始化快递员对象中 定区集合
  web层转Courier对象为json串时候,对象中有fixedareas集合属性,jpa加载策略延迟加载。
  在action中转fixedareas集合为json串,通过代理对象查询数据库,action中session已经关闭。

解决方案:不转fixedareas集合。

 

    /**
     * @Description: 快递员分页
     * @return
     * @throws Exception
     *      
     */
    @Action("courierAction_pageQuery")
    public String pageQuery() throws Exception {
        Pageable pageable = new PageRequest(page-1, rows);
        Page<Courier> page = courierService.findAll(pageable);
        
        Map<String, Object> map = new HashMap<>();
        map.put("total", page.getTotalElements());
        map.put("rows", page.getContent());
        
        //将fixedares集合属性排除掉,不转json
        JsonConfig jsonConfig = new JsonConfig();
        jsonConfig.setExcludes(new String[]{"fixedAreas"});
        
        String json = JSONObject.fromObject(map, jsonConfig).toString();
        
        ServletActionContext.getResponse().setContentType("text/json;charset=utf-8");
        ServletActionContext.getResponse().getWriter().write(json);
        return NONE;
    }

 

NoSession问题

标签:技术   ext   from   排除   images   spring   port   初始化   关闭   

原文地址:http://www.cnblogs.com/javaxiaoxin/p/7383112.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!