easyjweb框架的关联

package com.test.domain;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.OneToOne;
import com.easyjf.container.annonation.Field;
import javax.persistence.Id;
import javax.persistence.CascadeType;
import javax.persistence.JoinColumn;

@Entity
public class user {
	@Id
	@GeneratedValue(strategy = GenerationType.TABLE)
	private Long id;
	@Field(name = "用户名")
	private String userName;
	@Field(name = "密码")
	private String userPwd;
	@Field(name = "邮件")
	private String email;
	@OneToOne(cascade = CascadeType.ALL)
	@JoinColumn(name = "id", referencedColumnName = "userId")
	private dary dary;

	public dary getDary() {
		return dary;
	}

	public void setDary(dary dary) {
		this.dary = dary;
	}

	public Long getId() {
		return id;
	}

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

	public String getUserName() {
		return userName;
	}

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

	public String getUserPwd() {
		return userPwd;
	}

	public void setUserPwd(String userPwd) {
		this.userPwd = userPwd;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

}

上面引用了关联要用到的包如下:
import javax.persistence.OneToOne;
import com.easyjf.container.annonation.Field;
import javax.persistence.CascadeType;
import javax.persistence.JoinColumn;

然后是处理关联,这里测试的是OneTOOne关联
@OneToOne(cascade = CascadeType.ALL)
	@JoinColumn(name = "id", referencedColumnName = "userId")
	private dary dary;

	public dary getDary() {
		return dary;
	}

可以看出上面是本表的id跟dary表的userId是一对一的设置关系

然后在user的view那里再设置

<td title="$!info.dary.userText">$!info.dary.userText</td>

然后打包war再看一下 成功了吧 看到关联的userText没

你可能感兴趣的:(java,框架)