NoSession问题

第一种原因:

 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;
    }

 

 

EasyUi-TreeGrid展示菜单数据时的NoSession问题

 

 

 页面:pages/system/menu.jsp

 

问题一:由于要求返回json串中包含children  出现No-session

 

实体类中添加getChildren方法

解决:将子节点数据立即加载

 

 

问题二:json数据时候死循环

不转json的集合要排除掉,集合是默认延迟加载

把childrenMenus排除掉是为了解决NoSession问题,把parentMenu排除掉是为了解决死循环的问题

 

问题页面中出现重复数据

解决:修改MenuServiceImpl中的方法,只查询顶级节点

 

 

 

 

 

死循环示例:

如果用datagrid来显示联系人列表,Linkman中有属性:lkmId,lkmName,Customer对象,

转json后,出现死循环,解决:直接把customer干掉

 

 

posted on 2017-08-17 17:44  0001  阅读(699)  评论(0编辑  收藏  举报