본문 바로가기

백/전자정부프레임워크

전자정부 프레임워크4- update

2023.07.14 - [백/전자정부프레임워크] - 전자정부 프레임워크3- select, delete

 

전자정부 프레임워크3- select, delete

프로젝트는 egov_dept를 이어서 한다. insert는 전자정부 프레임워크2를 참고! 1.select 전체 목록 조회 sql.xml부터 dao package egovframework.example.sample.service.impl; import java.util.List; import org.springframework.stereotyp

codingzorim.tistory.com

 

3. update

deptDetail.jsp

<button type="button" onclick="location='deptModify.do?deptno=${deptVO.deptno}'">수정</button>

controller (기존 화면에서 바로 수정이 아니라 별도의 화면 띄울것)

	@RequestMapping(value = "/deptModify.do")
//	ModelMap : 전자정부 프레임워크는 model의 이름이 다르다
	public String deptModify(int deptno, ModelMap model) throws Exception {
		
		DeptVO vo = deptService.selectDeptDetail(deptno);
		model.addAttribute("deptVO", vo);
		
		return "dept/deptModify";
	}

deptModify.jsp(write를 복사함)

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style type="text/css">
		table{
			width: 400px;
			border-collapse: collapse;
		}
		th, td{
			border: 1px solid #cccccc;
			padding: 5px;
		}
	</style>
</head>
<body>
	<form action="deptModifySave.do" method="post">
		<table>
			<tr>
				<th>부서번호</th>
				<td><input type="text" name="deptno" value="${deptVO.deptno}" readonly></td>
			</tr>
			<tr>
				<th>부서이름</th>
				<td><input type="text" name="dname" value="${deptVO.dname}"></td>
			</tr>
			<tr>
				<th>부서위치</th>
				<td><input type="text" name="loc" value="${deptVO.loc}"></td>
			</tr>
			<tr align="center">
				<td colspan="2">
					<button type="submit">수정</button>
				</td>
			</tr>
		</table>
	</form>
</body>
</html>

 

sql.xml

<update id="deptDAO.updateDept">
		<![CDATA[
			UPDATE dept
			SET dname=#dname#
				, loc=#loc#
			WHERE deptno=#deptno#
		]]>
	</update>

dao.java

public void updateDept(DeptVO vo) throws Exception {
		update("deptDAO.updateDept", vo);
	}

service

void updateDept(DeptVO vo) throws Exception;

impl

	@Override
	public void updateDept(DeptVO vo) throws Exception {
		deptDAO.updateDept(vo);
	}

controller

@RequestMapping("/deptModifySave.do")
	public String updateDept(DeptVO vo) throws Exception {
		deptService.updateDept(vo);
		return "forward:/deptList.do";
	}