解决 jsonhibernate死循环 的 问题

xiaoxiao2021-02-28  34

两种简单的解决方式:

fastjson

@JSONField(serialize=false) @OneToMany(cascade = CascadeType.ALL, targetEntity=TDepartment.class, fetch = FetchType.LAZY, mappedBy = "pdemartnemt") public List<TDepartment> getDeparts() { return departs; } Gson @JSON(serialize=false) @OneToMany(cascade = CascadeType.ALL, targetEntity=TDepartment.class, fetch = FetchType.LAZY, mappedBy = "pdemartnemt") public List<TDepartment> getDeparts() { return departs; }

jsonConfig

JsonConfig jsonConfig = new JsonConfig(); jsonConfig.setIgnoreDefaultExcludes(false); //设置默认忽略 jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);//设置循环策略为忽略 jsonConfig.setExcludes(new String[] {"staffs"});//将所需忽略字段加到数组中
转载请注明原文地址: https://www.6miu.com/read-2624221.html

最新回复(0)