思路:将后台的实体用gson转换成json字符串,并用ModelMap 绑定到前台,然后解析对应的属性
1:所需要的jar包,谷歌的gson,处理json数据的
2:后台controller
@RequestMapping
public String showTable5Info(HttpServletRequest request,ModelMap map){
DynamicDataSourceHolder.setDataSource("dataSource_self");
//准备加载table5信息
FillIntellectual fillIntellectual=(FillIntellectual) baseDaoI.get("from FillIntellectual f where f.entinfoid=?",new Object[]{Integer.valueOf(request.getSession().getAttribute("entinfoid").toString())});
map.addAttribute("filljson", new Gson().toJson(fillIntellectual));
map.addAttribute("fillIntellectual", fillIntellectual);
return "/website/table5";
}
3:后台所对应的实体
package com.app.archive.model.shenbao;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Lob;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import java.util.Date;
@Entity
@Table(name="XED_FILL_INTELLECTUAL")
public class FillIntellectual{
@Id
@SequenceGenerator(name = "SEQ_XED_FILL_INTELLECTUAL", sequenceName = "SEQ_XED_FILL_INTELLECTUAL", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_XED_FILL_INTELLECTUAL")
/** 主键ID */
@Column(name="ID")
private Integer id;
/** 企业基础信息ID:指向xed_fill_entinfo表主键ID */
@Column(name="ENTINFOID")
private Integer entinfoid;
/** 是否有发明专利
0、无
1、有 */
@Column(name="ISINVENTION")
private Integer isinvention;
/** 发明专利数量 */
@Column(name="INVENTIONNUM")
private String inventionnum;
/** 是否有实用新型专利或外观设计专利
0、无
1、有 */
@Column(name="ISPRACTICAL")
private Integer ispractical;
/** 实用新型专利或外观设计专利数量 */
@Column(name="PRACTICALNUM")
private String practicalnum;
/** 是否有软件著作权
0、无
1、有 */
@Column(name="ISSOFTWARE")
private Integer issoftware;
/** 软件著作权数量 */
@Column(name="SOFTWARENUM")
private String softwarenum;
/** 是否有工程设计、产品设计、地、示意图等图形作品和模型著作权
0、无
1、有 */
@Column(name="ISENGINEERING")
private Integer isengineering;
/** 模型著作权数量 */
@Column(name="ENGINEERINGNUM")
private String engineeringnum;
/** 是否有原产地名称(地理标志)、植物新品种等其他类知识产区
0、无
1、有 */
@Column(name="ISNATIVE")
private Integer isnative;
/** 原产地名称数量 */
@Column(name="NATIVENUM")
private String nativenum;
/** 创建者ID:指向xed_member表主键ID */
@Column(name="CREATORID")
private Integer creatorid;
/** 创建时间 */
@Temporal(TemporalType.TIMESTAMP)
@Column(name="CREATETIME")
private Date createtime;
/**
* @return 主键ID
*/
public Integer getId() {
return this.id;
}
/**
* @param _id 主键ID
*/
public void setId(Integer _id) {
this.id = _id;
}
/**
* @return 企业基础信息ID:指向xed_fill_entinfo表主键ID
*/
public Integer getEntinfoid() {
return this.entinfoid;
}
/**
* @param _entinfoid 企业基础信息ID:指向xed_fill_entinfo表主键ID
*/
public void setEntinfoid(Integer _entinfoid) {
this.entinfoid = _entinfoid;
}
/**
* @return 是否有发明专利
0、无
1、有
*/
public Integer getIsinvention() {
return this.isinvention;
}
/**
* @param _isinvention 是否有发明专利
0、无
1、有
*/
public void setIsinvention(Integer _isinvention) {
this.isinvention = _isinvention;
}
/**
* @return 发明专利数量
*/
public String getInventionnum() {
return this.inventionnum;
}
/**
* @param _inventionnum 发明专利数量
*/
public void setInventionnum(String _inventionnum) {
this.inventionnum = _inventionnum;
}
/**
* @return 是否有实用新型专利或外观设计专利
0、无
1、有
*/
public Integer getIspractical() {
return this.ispractical;
}
/**
* @param _ispractical 是否有实用新型专利或外观设计专利
0、无
1、有
*/
public void setIspractical(Integer _ispractical) {
this.ispractical = _ispractical;
}
/**
* @return 实用新型专利或外观设计专利数量
*/
public String getPracticalnum() {
return this.practicalnum;
}
/**
* @param _practicalnum 实用新型专利或外观设计专利数量
*/
public void setPracticalnum(String _practicalnum) {
this.practicalnum = _practicalnum;
}
/**
* @return 是否有软件著作权
0、无
1、有
*/
public Integer getIssoftware() {
return this.issoftware;
}
/**
* @param _issoftware 是否有软件著作权
0、无
1、有
*/
public void setIssoftware(Integer _issoftware) {
this.issoftware = _issoftware;
}
/**
* @return 软件著作权数量
*/
public String getSoftwarenum() {
return this.softwarenum;
}
/**
* @param _softwarenum 软件著作权数量
*/
public void setSoftwarenum(String _softwarenum) {
this.softwarenum = _softwarenum;
}
/**
* @return 是否有工程设计、产品设计、地、示意图等图形作品和模型著作权
0、无
1、有
*/
public Integer getIsengineering() {
return this.isengineering;
}
/**
* @param _isengineering 是否有工程设计、产品设计、地、示意图等图形作品和模型著作权
0、无
1、有
*/
public void setIsengineering(Integer _isengineering) {
this.isengineering = _isengineering;
}
/**
* @return 模型著作权数量
*/
public String getEngineeringnum() {
return this.engineeringnum;
}
/**
* @param _engineeringnum 模型著作权数量
*/
public void setEngineeringnum(String _engineeringnum) {
this.engineeringnum = _engineeringnum;
}
/**
* @return 是否有原产地名称(地理标志)、植物新品种等其他类知识产区
0、无
1、有
*/
public Integer getIsnative() {
return this.isnative;
}
/**
* @param _isnative 是否有原产地名称(地理标志)、植物新品种等其他类知识产区
0、无
1、有
*/
public void setIsnative(Integer _isnative) {
this.isnative = _isnative;
}
/**
* @return 原产地名称数量
*/
public String getNativenum() {
return this.nativenum;
}
/**
* @param _nativenum 原产地名称数量
*/
public void setNativenum(String _nativenum) {
this.nativenum = _nativenum;
}
/**
* @return 创建者ID:指向xed_member表主键ID
*/
public Integer getCreatorid() {
return this.creatorid;
}
/**
* @param _creatorid 创建者ID:指向xed_member表主键ID
*/
public void setCreatorid(Integer _creatorid) {
this.creatorid = _creatorid;
}
/**
* @return 创建时间
*/
public Date getCreatetime() {
return this.createtime;
}
/**
* @param _createtime 创建时间
*/
public void setCreatetime(Date _createtime) {
this.createtime = _createtime;
}
}
4:前台解析
//加载
$(function(){
var fillIntellectual=${filljson};
if(fillIntellectual.isinvention==1){
$("#isinvention_1").prop("checked", "checked");
}else{
$("#isinvention_0").prop("checked", "checked");
}
if(fillIntellectual.ispractical==1){
$("#ispractical_1").prop("checked", "checked");
}else{
$("#ispractical_0").prop("checked", "checked");
}
if(fillIntellectual.issoftware==1){
$("#issoftware_1").prop("checked", "checked");
}else{
$("#issoftware_0").prop("checked", "checked");
}
if(fillIntellectual.isengineering==1){
$("#isengineering_1").prop("checked", "checked");
}else{
$("#isengineering_0").prop("checked", "checked");
}
if(fillIntellectual.isnative==1){
$("#isnative_1").prop("checked", "checked");
}else{
$("#isnative_0").prop("checked", "checked");
}
// alert(fillIntellectual.isinvention+","+fillIntellectual.inventionnum);
});