(struts2注解)
表关系图如下:
TB_User实体类如下:
@Entity
@Table(name = "C_USER", schema = "YL")
@SequenceGenerator(name="cuser",sequenceName="SEQ_CUSER_ID",allocationSize = 1)
public class CUser implements java.io.Serializable {
// Fields
private Integer id;
private String username;
private String password;
private Set<CUserCard> tbUserCards = new HashSet<CUserCard>(0);
//...................省
}
通过struts2的json数据类型返回TB_User对象时,需要排除一对多关系属性,防止序列化死循环,
代码如下:
@Action(value="getUser",results={@Result(name="success",type="json",params={"root","resultMap","excludeProperties","user\\.tbUserRooms"})})
public String getUser(){
//........
return SUCCESS;
}
因为软件需要,增加了表Tb_Room,该表和 Tb_User表也存在多对多关系,关系图如下:
TB_User实体类如下:
@Entity
@Table(name = "C_USER", schema = "YL")
@SequenceGenerator(name="cuser",sequenceName="SEQ_CUSER_ID",allocationSize = 1)
public class CUser implements java.io.Serializable {
// Fields
private Integer id;
private String username;
private String password;
private Set<CUserCard> tbUserCards = new HashSet<CUserCard>(0);
private Set<CUserRoom> tbUserRooms = new HashSet<CUserRoom>(0);
//...................省
}
现在,在返回Tb_Users对象时,有两个需要排除的属性:tbUserRooms和tbUserCards。
这时候,注解语句该怎么写?
如果排除的不止一个对象,excludeProperties的正则表达式怎么写?
之前试过用逗号分隔,还是没有解决
struts json 正则表达式 excludeProperties
------解决方案--------------------
怎么你手动清除下关系就可以:
比如 A中有list<B> blist
B中有A a
在使用A生成json之前,
for(B b:b){
b.setA(null);
}
就可以,