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'
		})
	}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章