Hibernate前台页面的数据回显

解释说明:我做的这个项目就是数据回显,回显的是数据库中字典表的值

1.首先就是在controller的文件中获得到每个回显的数据

    /**
	 * 从字典表中查询教师的学位
	 * @return
	 */
	@RequestMapping("degree")
	public List<Dictionary> finddictionary() {
		return DictionaryCacheUtil.findByCode("degree");//这是数据库中的字段名称
	}

	/**
	 * 从字典表中查询教师的学历
	 * @return
	 */
	@RequestMapping("eduBack")
	public List<Dictionary> findeduBack() {
		return DictionaryCacheUtil.findByCode("eduBack");
	}

	/**
	 * 从字典表中查询教师的职务
	 * @return
	 */
	@RequestMapping("post")
	public List<Dictionary> findpost() {
		return DictionaryCacheUtil.findByCode("post");
	}

	/**
	 * 从字典表中查询教师的类型
	 * @return
	 */
	@RequestMapping("type")
	public List<Dictionary> findtype() {
		return DictionaryCacheUtil.findByCode("type");
	}
	
	/**
	 * 从字典表中查询教师的职称
	 * @return
	 */
	@RequestMapping("title")
	public List<Dictionary> findtitle(){
		return DictionaryCacheUtil.findByCode("title");
	}

2.在jsp文件中写上有关的代码

<td class="td_marked">学位:</td>
<td class="td_content">
	<input id="seldegree" name="degree" style="width: 150px" />
</td>

<td class="td_marked">学历:</td>
<td class="td_content">
	<input id="seledu" name="eduBack" style="width: 150px" />
</td>

<td class="td_marked">职务:</td>
<td class="td_content">
	<input id="selpost" name="post" style="width: 150px" />
</td>

<td class="td_marked">职称:</td>
<td class="td_content">
	<input id="seltitle" name="title" style="width: 150px" />
</td>

<td class="td_marked">类别:</td>
<td class="td_content">
	<input id="seltype" name="type" style="width: 150px" />
</td>

3.接下来就是在js文件中接收后台查询回来的数据然后显示在前台

//在URL中的都是跟后台对接的路径
var url = {
		degree : serverBasePath + "/teachers/degree",
		eduBack : serverBasePath + "/teachers/eduBack",
		post : serverBasePath + "/teachers/post",
		type : serverBasePath + "/teachers/type",
		title : serverBasePath + "/teachers/title",
	}    

/**在弹出新增的弹框的时候,显示出数据回显的默认的值
	 * 新增教师
	 */
	function add() {
		$("#form").form("clear");
		$('#seldept').combobox({
			value : "请选择系别"
		});
		$('#selmajor').combobox({
			value : "请选择专业"
		});
		$("#txshow").attr("src", "");
		$('#dialog').dialog('open');

		//给定字典表中的回显一个默认值(学位)
		var degreeData = $("#seldegree").combobox("getData");
		DataList(degreeData, "seldegree");

		//学历
		var degreeData = $("#seledu").combobox("getData");
		DataList(degreeData, "seledu");

		//职务
		var degreeData = $("#selpost").combobox("getData");
		DataList(degreeData, "selpost");

		//类型
		var degreeData = $("#seltype").combobox("getData");
		DataList(degreeData, "seltype");
		
		//职称
		var degreeData = $("#seltitle").combobox("getData");
		DataList(degreeData, "seltitle");
		
		$('#code').attr('readonly',false);
		$('#code').tooltip({
		    position: 'right',
		    content: '<span style="color:#fff">提交后,编号不可再修改</span>',
		    onShow: function(){
				$(this).tooltip('tip').css({
					backgroundColor: '#666',
					borderColor: '#666'
				});
		    }
		});

	}

    /**
	 * 增加学历的回显
	 */
	function seledu() {
		$('#seledu').combobox({
			url : url.eduBack,//连接对应的路径
			panelHeight : 'auto',
			valueField : 'value',
			editable : false,
			textField : 'text'
		})
	}

	/**
	 * 增加职务的回显
	 */
	function selpost() {
		$('#selpost').combobox({
			url : url.post,
			panelHeight : 'auto',
			valueField : 'value',
			editable : false,
			textField : 'text'
		})
	}

	/**
	 * 增加类别的类型
	 */
	function seltype() {
		$('#seltype').combobox({
			url : url.type,
			panelHeight : 'auto',
			valueField : 'value',
			editable : false,
			textField : 'text'
		})
	}
	
	/**
	 * 增加职称的回显
	 */
	function seltitle() {
		$('#seltitle').combobox({
			url : url.title,
			panelHeight : 'auto',
			valueField : 'value',
			editable : false,
			textField : 'text'
		})
	}

猜你喜欢

转载自blog.csdn.net/cxc_happy111/article/details/81414655
今日推荐