实体转为json的,如何处理外键情况

实体转为json的,如何处理外键情况

jc.registerJsonValueProcessor(Userrelation.class,
				new JsonValueProcessor() {// 此处的Role是Role对象的外键属性
					public Object processObjectValue(
							String key, Object value,
							JsonConfig arg2) {
						if (value == null)
							return "属性为空值";
						if (value instanceof Userrelation) {
							String cname = ((Userrelation) value).getC_person().getName();//获得测评人的姓名
							String bname=((Userrelation) value).getB_person().getName();//获得被测评人的姓名
							return cname+"->"+bname;
						}
						return value.toString();
					}

					public Object processArrayValue(
							Object value, JsonConfig arg1) {
						return "";
					}
				});

  

原文地址:https://www.cnblogs.com/oymx/p/4019373.html