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条回答 默认 最新

  • Go 旅城通票 2017-06-27 05:26
    关注

    配置dataReader field的mapping属性隐射到子json对象属性去就行了

    有用记得采纳:)

    http://docs.sencha.com/extjs/4.1.3/#!/api/Ext.data.Field-cfg-mapping

      Ext.define('ModelName', {
                extend: 'Ext.data.Model',
                fields: ["username",
                    { "name": "deparName", mapping: "depart.deparName" }//如果还有其他内嵌JSON对象按照这个进行隐射
                ]
            });
    
                    {
        text:'部门名称',
        width: 100,
        dataIndex:'deparName'/////直接配置为model中定义的field名称就行
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 爬取豆瓣电影相关处理
  • ¥15 手机淘宝抓清除消息接口
  • ¥15 C#无selenium
  • ¥15 LD衰减计算的结果过大
  • ¥15 用机器学习方法帮助保险公司预测哪些是欺诈行为
  • ¥15 计算300m以内的LD衰减
  • ¥15 数据爬取,python
  • ¥15 怎么看 cst中一个面的功率分布图,请说明详细步骤。类似下图
  • ¥15 为什么我的pycharm无法用pyqt6的QtWebEngine
  • ¥15 FOR循环语句显示查询超过300S错误怎么办