hibernate传递给前台json数据的时候有些数据不匹配的解决方法

1.很简单的,不用再添加什么其余的对象,直接就是在原来的对象里添加需要的数据就好了,一定要添加set和get方法。但是后台不需要在进行配置就行了。


2.代码

package com.marvin.book.pojo;

import java.util.HashSet;
import java.util.Set;

/**
 * Booktype entity. @author MyEclipse Persistence Tools
 */

public class Booktype implements java.io.Serializable {

	private static final long serialVersionUID = -4161453077878631323L;
	private int id;
	private String text;
	private String description;
	private boolean leaf;
	private Booktype booktype;
	private boolean expandable;
	private int parent = (this.booktype!=null)?this.booktype.getId():0;
	private Set books = new HashSet(0);
	private Set children = new HashSet(0);
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getText() {
		return text;
	}
	public void setText(String text) {
		this.text = text;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	public boolean isLeaf() {
		return leaf;
	}
	public void setLeaf(boolean leaf) {
		this.leaf = leaf;
	}
	public Booktype getBooktype() {
		
		return booktype;
	}
	public void setBooktype(Booktype booktype) {
		this.booktype = booktype;
		//精华就在这里哟   关系说明   将一个关联的对象转化为一个列传到前台,千万注意是在这个列所依靠的属性的set方法里面进行赋值啊
		this.parent = (this.booktype!=null)?this.booktype.getId():0;
	}
	public boolean isExpandable() {
		return expandable;
	}
	public void setExpandable(boolean expandable) {
		this.expandable = expandable;
	}
	public int getParent() {
		return parent;
	}
	public void setParent(int parent) {
		this.parent = (this.booktype!=null)?this.booktype.getId():0;
	}
	public Set getBooks() {
		return books;
	}
	public void setBooks(Set books) {
		this.books = books;
	}
	public Set getChildren() {
		return children;
	}
	public void setChildren(Set children) {
		this.children = children;
	}
	public Booktype(int id, String text, String description, boolean leaf,
			Booktype booktype, boolean expandable, int parent, Set books,
			Set children) {
		super();
		this.id = id;
		this.text = text;
		this.description = description;
		this.leaf = leaf;
		this.booktype = booktype;
		this.expandable = expandable;
		this.parent = parent;
		this.books = books;
		this.children = children;
		this.parent = (this.booktype!=null)?this.booktype.getId():parent;
	}
	public Booktype() {
		super();
		// TODO Auto-generated constructor stub
	}
	
	
}

意思就是说,添加的数据一定要从他的父亲进行添加,要是有父亲,就一定有孩子。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值