溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

怎么用SSM框架實(shí)現(xiàn)信息管理系統(tǒng)

發(fā)布時(shí)間:2022-09-30 13:42:35 來源:億速云 閱讀:126 作者:iii 欄目:開發(fā)技術(shù)

本篇內(nèi)容介紹了“怎么用SSM框架實(shí)現(xiàn)信息管理系統(tǒng)”的有關(guān)知識(shí),在實(shí)際案例的操作過程中,不少人都會(huì)遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

1.首先我們創(chuàng)建數(shù)據(jù)庫

怎么用SSM框架實(shí)現(xiàn)信息管理系統(tǒng)

2.在jdbc.properties里配置數(shù)據(jù)庫信息

怎么用SSM框架實(shí)現(xiàn)信息管理系統(tǒng)

3.創(chuàng)建User這個(gè)實(shí)體類,與sql表做映射

怎么用SSM框架實(shí)現(xiàn)信息管理系統(tǒng)

4.在dao層寫一個(gè)接口,里面是增刪改查的方法,并且在service層實(shí)現(xiàn)這個(gè)接口

怎么用SSM框架實(shí)現(xiàn)信息管理系統(tǒng)

怎么用SSM框架實(shí)現(xiàn)信息管理系統(tǒng)

5.在usermapper.xml文件

(1)在usermapper.xml文件里寫數(shù)據(jù)庫信息

怎么用SSM框架實(shí)現(xiàn)信息管理系統(tǒng)

(2)在usermapper.xml里寫更改的sql語句(以更改為例)

	<select id="findById" parameterType="edu.jmi.bean.User" resultMap="BaseResultMap">		select * from user		where id = #{id}
	</select>
	<update id="update" parameterType="edu.jmi.bean.User">
		update User set
		username = #{record.username,jdbcType=VARCHAR},
		password = #{record.password,jdbcType=VARCHAR},
		phone = #{record.phone,jdbcType=VARCHAR},
		address = #{record.address,jdbcType=VARCHAR},
		score = #{record.score,jdbcType=INTEGER}
		where id = #{id}
	</update>

這里要注意的是,更改是先查詢出結(jié)果,再進(jìn)行修改,所以需要兩條語句

然后在usercontroller這個(gè)類里編寫方法

	//跳轉(zhuǎn)到更改界面
	@RequestMapping("/updateUserTo")	public String findById(HttpServletRequest request,Integer id) {
		User record = userService.findById(id);
		request.getSession().setAttribute("record", record);		return "/user/updateUser";
	}	
	//更改信息
	@RequestMapping("/User/updateUser")	public String updateUser(HttpServletRequest request,
			@Param("id") Integer id) {
		User record = new User();
		record.setUsername(request.getParameter("username"));
		record.setPassword(request.getParameter("password"));
		record.setPhone(request.getParameter("phone"));
		record.setAddress(request.getParameter("address"));
		record.setScore((Integer.parseInt(request.getParameter("score"))));
		userService.update(record, id);		return "redirect:/User/UserPage";
	}

6.我們創(chuàng)建三個(gè)jsp文件,分別用來顯示首頁,更改頁面, 和運(yùn)行頁面

<table align="center">
	<th>學(xué)號(hào)</th>
	<th>姓名</th>
	<th>密碼</th>
	<th>手機(jī)</th>
	<th>課程</th>
	<th>分?jǐn)?shù)</th>
	<th>操作</th>
	<c:forEach items="${pageInfo.list}" var="user">
		<tr>
			<td style="border:1px solid red;width:100px;height:15px;text-align:center">${user.id}</td>
			<td style="border:1px solid red;width:100px;height:15px;text-align:center">${user.username}</td>
			<td style="border:1px solid red;width:100px;height:15px;text-align:center">${user.password}</td>
			<td style="border:1px solid red;width:100px;height:15px;text-align:center">${user.phone}</td>
			<td style="border:1px solid red;width:100px;height:15px;text-align:center">${user.address}</td>
			<td style="border:1px solid red;width:100px;height:15px;text-align:center">${user.score}</td>
			<td><a href="${currentPath}/deleteById?id=${user.id}">刪除</a>
			<a href="${currentPath}/updateUserTo?id=${user.id}">更改</a>
			<a href="${currentPath}/addUserTo">添加</a>
			</td>
		</tr>
	</c:forEach></table>
<form action="${pageContext.request.contextPath}/User/updateUser" method="post" >
	學(xué)號(hào):<input type="hidden" name="id" value="${record.id }"><br><br>
	姓名:<input type="text" name="username" value="${record.username}"><br><br>
	密碼:<input type="text" name="password" value="${record.password}"><br><br>
	手機(jī):<input type="text" name="phone" value="${record.phone}"><br><br>
	課程:<input type="text" name="address" value="${record.address}"><br><br>
	分?jǐn)?shù):<input type="text" name="score" value="${record.score}"><br><br>
	<button type="submit" >提交</button>&nbsp;&nbsp;	<button type="reset" >清空</button></form>
<jsp:forward page="./User/UserPage"></jsp:forward>

7.結(jié)果

怎么用SSM框架實(shí)現(xiàn)信息管理系統(tǒng)

“怎么用SSM框架實(shí)現(xiàn)信息管理系統(tǒng)”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

ssm
AI