logeed1 2017-06-27 04:35 采纳率: 25%
浏览 910
已采纳

extjs5 hibernate实体关联 值怎么引用?

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

/**

  • User entity. @author MyEclipse Persistence Tools
    */
    @Entity
    @Table(name = "user", catalog = "thinkdb")
    public class User implements java.io.Serializable {

    // Fields

    private Long id;
    private Depart depart;
    private String userName;

    // Constructors

    /** default constructor */
    public User() {
    }

    /** full constructor */
    public User(Depart depart, String userName) {
    this.depart = depart;
    this.userName = userName;
    }

    // Property accessors
    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "id", unique = true, nullable = false)
    public Long getId() {
    return this.id;
    }

    public void setId(Long id) {
    this.id = id;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "depart_id")
    public Depart getDepart() {
    return this.depart;
    }

    public void setDepart(Depart depart) {
    this.depart = depart;
    }

    @Column(name = "user_name", length = 50)
    public String getUserName() {
    return this.userName;
    }

    public void setUserName(String userName) {
    this.userName = userName;
    }

}

import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**

  • Depart entity. @author MyEclipse Persistence Tools
    */
    @Entity
    @Table(name = "depart", catalog = "thinkdb")
    public class Depart implements java.io.Serializable {

    // Fields

    private Long id;
    private String departName;
    private Set users = new HashSet(0);

    // Constructors

    /** default constructor */
    public Depart() {
    }

    /** full constructor */
    public Depart(String departName, Set users) {
    this.departName = departName;
    this.users = users;
    }

    // Property accessors
    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "id", unique = true, nullable = false)
    public Long getId() {
    return this.id;
    }

    public void setId(Long id) {
    this.id = id;
    }

    @Column(name = "depart_name", length = 50)
    public String getDepartName() {
    return this.departName;
    }

    public void setDepartName(String departName) {
    this.departName = departName;
    }

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "depart")
    public Set getUsers() {
    return this.users;
    }

    public void setUsers(Set users) {
    this.users = users;
    }

}

EXTJS

//表格

columns:[
{
    text:'用户名',
    width: 80,
    dataIndex:'username'
},
{
    text:'部门名称',
    width: 100,
    dataIndex:'depart.deparName',//这里如何拿到部门名称 model 字段如何配置可以实现  depart.deparName 取值             
}
],
  • 写回答

1条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥250 python的exchangelib 报错
      • ¥15 Oracle外部过程获取的句柄属性为空
      • ¥20 snmpv3相关提问
      • ¥20 boost电路升压频率和占空比选择
      • ¥15 找个人工智能的大佬咨询一些毕设问题
      • ¥15 需要教程:GD32F450I移植无系统lwip
      • ¥15 中文语料库检索构式 求助
      • ¥15 关于naver点击量信息
      • ¥15 Linux gcc升级问题
      • ¥100 如何封禁域名,让app打不开呢?