본문 바로가기
공부기록/Java

전자정부프레임워크 - 샘플

by project100 2023. 10. 29.

deptWrite.jsp

<head>
<style>
	table {
	width: 400px;
	border-collapse:collapse;
	}
	th, td {
	borderL 1px solid #ccc;
	padding:5px;
	}
</style>
</head>

<body>
        <form name="frm" method="post" action="deptWriteSave.do">
        <table>
        <tr>
        <th>부서번호</th>
        <td><input type="text" name="deptno"></td>
        </tr>
        <tr>
        <th>부서이름</th>
        <td><input type="text" name="dname"></td>
        </tr>
        <tr>
        <th>부서위치</th>
        <td><input type="texpt" name="loc"></td>
        </tr>
        <tr>
        <th colspan="2">
        <button type="submit">저장</button>
        </th>
        </tr>
        </table>
        </form>
</body>

deptList.jsp

//jsp 경로 복사해오기

<head>
<style>
	table {
	width: 400px;
	border-collapse:collapse;
	}
	th, td {
	borderL 1px solid #ccc;
	padding:5px;
	}
</style>
</head>

<body>
        <table>
        <caption>목록</caption>
        <tr>
        <th>부서번호</th>
        <th>부서이름</th>
        <th>부서위치</th>
        </tr>
        
        <c:forEach var="result" items="${resultList}" varStatus="status">
        <tr>
         <td>${result.deptno}</td>
         <td><a href="deptDetail.do?deptno=${result.deptno}">${result.dname}</td>
         <td>${result.loc}</td>
         </tr>
        </c:forEach>
        </table>  
</body>

 

deptDetail.jsp

// jsp 경로 복사

<head>
<style>
	table {
	width: 400px;
	border-collapse:collapse;
	}
	th, td {
	borderL 1px solid #ccc;
	padding:5px;
	}
</style>
</head>

<body>
        <table>
        <tr>
        <th>부서번호</th>
        <td>${deptVo.deptno}</td>
        </tr>
        <tr>
        <th>부서이름</th>
        <td>${deptVo.dname}</td>
        </tr>
        <tr>
        <th>부서위치</th>
        <td>${deptVo.loc}</td>
        </tr>
        <tr>
        <th colspan="2">
        <button type="button" onclick="location='deptModifyWrite.do?deptno=${deptVo.deptno}'">수정</button>
        <button type="button" onclick="location='deptDelete.do?deptno=${deptVo.deptno}'">삭제</button>
        </th>
        </tr>
        </table>
</body>

 

deptModifyWrite.jsp

// jsp 경로 복사

<head>
<style>
	table {
	width: 400px;
	border-collapse:collapse;
	}
	th, td {
	borderL 1px solid #ccc;
	padding:5px;
	}
</style>
</head>

<body>
        <form name="frm" method="post" action="deptModifySave.do">
        <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>
        <th colspan="2">
        <button type="submit">저장</button>
        </th>
        </tr>
        </table>
        </form>
</body>

 

 

controller

 

@어노테이션 import 시키기

@Controller
public class DeptController {

    @Resource(name="deptService")
    private DeptService deptService;


    // jsp 연결
    @RequestMapping(value="/deptWrite.do")
    public String deptWrite() {
    return "dept/deptWrite";
    }

    // 저장
    @RequsetMapping(value="deptWriteSave.do")
    public String insertDept(DeptVo vo) throws Exception {
    String result = deptService.InsertDept(vo);
    if(result == null ){
     System.out.println("저장완료");
    } else {
     System.out.println("저장실패");
    }
    return "";
    }
    
    // 목록
    @RequsetMapping(value="/deptList.do")
    public String selectDeptList(DeptVo vo, ModelMap model) throws Exception {
    List<?> list = deptSevice.SelectDeptList(vo);
    model.addAttribute("resultList", list);
    return "dept/deptList";
    }
    
    // 상세
    @RequsetMapping(value="/deptDetail.do")
    public String selectDeptDetail(int deptno, ModelMap model) throws Exception {
    DeptVo vo = deptSevice.SelectDeptDetail(deptno);
    model.addAttribute("deptVo", vo);
    return "dept/deptDetail";
    }
    
    // 삭제
    @RequstMapping(value="/deptDelete.do")
    public String deleteDept(int deptno) throws Exception {
    int result = deptService.deleteDept(deptno);
    if(result == 1){
     System.out.println("삭제완료");
    } else {
     System.out.println("삭제실패");
    }
    return ""; 
    }
    
    // 수정
    @RequsetMapping(value="/deptModifyWrite.do")
    public String selectDeptModify(int deptno, ModelMap model) throws Exception {
    DeptVo vo = deptSevice.SelectDeptDetail(deptno); // 상세와 service가 같음
    model.addAttribute("deptVo", vo);
    retrun "dept/deptModifyWirte";
    }
    
    // 수정저장
    @RequsetMapping(value="/deptModifySave.do")
    public String updateDept(DeptVo vo) throws Exception {
    int result = deptService.updateDept(vo);
    if(result == 1){
     System.out.println("수정완료");
    } else {
     System.out.println("수정실패");
    }
    return ""; 
}

 

DeptVo

public class DeptVo {

	private String deptno;
	private String dname;
	private String loc;

// get, set 꼭 만들기 
// 우클릭 Source - generate getters and setters 

}

 

Service - interface

List import 처리

public interface DeptService {
    // 저장
    public String insertDept(DeptVo vo) throws Exception;

    // 목록
    public List<?> selectDeptList(DeprVo vo) throws Exception;
    
    // 상세
    public DeptVo selectDeptDetail(int deptno) throws Exception;
    
    // 삭제
    public int deleteDept(int deptno) throws Exception;
    
    // 수정
    public int updateDept(DeptVo vo) throws Exception;
}

 

ServiceImpl - 프로그램 구현

// DeptService, DeptVo import 

@Service("deptService")
public class DeptServiceImpl extends EgovAbstractServiceImpl implements DeptService {
    @Resource(name ="deptDAO")
    private DeptDAO deptDAO;

	// 저장
    @Override
    public String insertDept(DeptVo vo) throws Exception {
    return deptDAO.insertDept(vo); 
    }
    
    // 목록
    @Override
    public List<?> selectDeptList(DeptVo vo) throws Exception {
    return deptDAO.selectDeptList(vo);
    }

	// 상세
    @Override
    public DeptVo selectDeptDetail(int deptno) throws Exception {
    return deptDAO.selectDeptDetail(deptno); 
    }
    
    // 삭제
    @Override
    public int deleteDept(int deptno) throws Exception {
    return deptDAO.deleteDept(deptno); 
    }
    
    // 수정
    @Override
    public int updateDept(DeptVo vo) throws Exception {
    return deptDAO.updateDept(vo); 
    }
}

 

DeptDAO

@Repository("deptDAO")
public class DeptDAO extends EgovAbstractDAO {
	// 저장
    public String insertDept(DeptVo vo) {
    return (String) insert("deptDAO.InsertDept", vo);
    }
    
    // 목록
    public List<?> selectDeptList(DeptVo vo) {
    return (List<?>) list("deptDAO.selectDeptList", vo);
    }
    
    // 상세
    public DeptVo selectDeptDetail(int deptno) {
    return (DeptVo) select("deptDAO.selectDeptDetail", deptno);
    }
    
    // 삭제
    public int deleteDept(int deptno) {
    return (int) delete("deptDAO.deleteDept", deptno);
    }
    
    // 수정
    public int updateDept(DeptVo vo) {
    return (int) update("deptDAO.updateDept", vo);
    }
}

 

 

sqlMap파일

Dept_SQL.xml

<sqlMap namespace="Dept"> // 테이블이름

// <typeAlias> 두개 복사 후 이름 변경
	// 저장
    <insert id="deptDAO.InsertDept">
    insert into dept(deptno, dname, loc) valuse( #deptno#, #dname#, #loc# )
    </insert>

	// 목록
    <select id="deptDAO.SelectDeptList" resultClass="egovMap">
    select deptno, dname, loc from dept
    </select>
    
    // 상세
    <select id="deptDAO.SelectDeptDetail" resultClass="deptVo">
    select deptno, dname, loc from dept where detpno=#deptno#
    </select>
    
    // 삭제
    <delete id="deptDAO.deleteDept">
    delete from dept where deptno=#deptno#
    </delete>
    
    // 수정
    <update id="deptDAO.updateDept">
    update dept set dname=#danme#, loc=#loc# where deptno=#deptno#
    </update>
</sqlMap>

sql-map-config.xml

경로 작성하기 Dept_SQL.xml 

 

'공부기록 > Java' 카테고리의 다른 글

11월 25일 eclipse - java  (0) 2023.11.25
11월 4일 Java - eclipse  (0) 2023.11.05
10월 22일 Java - eclipse  (0) 2023.10.25
10월 21일 Java - eclipse  (1) 2023.10.21
10월 15일 Java - eclipse  (0) 2023.10.15