전자정부프레임워크 게시판 기본(4)
2020. 12. 22. 16:07
728x90
DB SQL문 Eclipse에서 사용
방법1
① eGovFrame > Database Conecctions > new > oracle 정보 입력 > 생성
② src>main>resources>db>sql file 생성

방법2
① src>main>resources>egovframework>sqlmap>example>mappers>xml file 생성
② src>main>java>egovframework>example>board>service>impl>BoardMapper.java 생성
③ sample -> 지정이름(board)으로 변경
④ src>main>resources>egovframework>sqlmap>example>sql-mapper-config.xml 수정
⑤ src>main>java>egovframework>example>board>service>impl>BoardServiceImpl.java 생성
Board_SQL.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="egovframework.example.board.service.impl.BoardMapper">
<resultMap id="board" type="egovframework.example.board.service.BoardVO">
<result property="idx" column="idx"/>
<result property="subject" column="subject"/>
<result property="contents" column="contents"/>
<result property="count" column="count"/>
<result property="write" column="write"/>
<result property="indate" column="indate"/>
</resultMap>
<insert id="insertBoard" parameterType="BoardVO">
INSERT INTO tb_board
( IDX
, SUBJECT
, CONTENT
, COUNT
, WRITE
, INDATE)
VALUES ( #{tb_board_seq.NEXTVAL, jdbcType=VARCHAR}
, #{subject, jdbcType=VARCHAR}
, #{content, jdbcType=VARCHAR}
, #{count, jdbcType=VARCHAR}
, #{write, jdbcType=VARCHAR}
, sysdate() )
</insert>
<update id="updateBoard">
UPDATE tb_board
SET subject=#{subject}
, content=#{content}
WHERE IDX=#{idx}
</update>
<delete id="deleteBoard">
DELETE FROM tb_board
WHERE IDX=#{idx}
</delete>
<select id="selectBoard" resultMap="board">
SELECT
a.IDX, a.subject, a.content, a.count, a.write, a.indate, b.user_name
FROM tb_board A LEFT JOIN tb_user B ON A.writer = B.user_id
WHERE IDX=#{idx}
</select>
<select id="selectBoardList" parameterType="searchVO" resultType="egovMap">
SELECT
a.IDX, a.subject, a.content, a.count, a.write, a.indate, b.user_name
FROM tb_board A LEFT JOIN tb_user B ON A.writer = B.user_id
WHERE 1=1
<if test="searchKeyword != null and searchKeyword != ''">
<choose>
<when test="searchCondition == 0">
AND IDX LIKE '%' || #{searchKeyword} || '%'
</when>
<when test="searchCondition == 1">
AND subject LIKE '%' || #{searchKeyword} || '%'
</when>
</choose>
</if>
ORDER BY IDX ASC
LIMIT #{recordCountPerPage} OFFSET #{firstIndex}
</select>
<select id="selectBoardListTotCnt" parameterType="searchVO" resultType="int">
SELECT COUNT(*) totcnt
FROM tb_board
WHERE 1=1
<if test="searchKeyword != null and searchKeyword != ''">
<choose>
<when test="searchCondition == 0">
AND IDX LIKE '%' || #{searchKeyword} || '%'
</when>
<when test="searchCondition == 1">
AND subject LIKE '%' || #{searchKeyword} || '%'
</when>
</choose>
</if>
</select>
</mapper>
sql-mapper-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<typeAliases>
<typeAlias alias="egovMap" type="egovframework.rte.psl.dataaccess.util.EgovMap"/>
<typeAlias alias="searchVO" type="egovframework.example.board.service.BoardDefaultVO"/>
<typeAlias alias="BoardVO" type="egovframework.example.board.service.BoardVO"/>
</typeAliases>
</configuration>
BoardDAO.java
/*
* Copyright 2008-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package egovframework.example.board.service.impl;
import java.util.List;
import egovframework.example.board.service.BoardDefaultVO;
import egovframework.example.board.service.BoardVO;
import egovframework.rte.psl.dataaccess.EgovAbstractDAO;
import org.springframework.stereotype.Repository;
/**
* @Class Name : SampleDAO.java
* @Description : Sample DAO Class
* @Modification Information
* @
* @ 수정일 수정자 수정내용
* @ --------- --------- -------------------------------
* @ 2009.03.16 최초생성
*
* @author 개발프레임웍크 실행환경 개발팀
* @since 2009. 03.16
* @version 1.0
* @see
*
* Copyright (C) by MOPAS All right reserved.
*/
@Repository("boardDAO")
public class BoardDAO extends EgovAbstractDAO {
/**
* 글을 등록한다.
* @param vo - 등록할 정보가 담긴 SampleVO
* @return 등록 결과
* @exception Exception
*/
public String insertBoard(BoardVO vo) throws Exception {
return (String) insert("boardDAO.insertBoard", vo);
}
/**
* 글을 수정한다.
* @param vo - 수정할 정보가 담긴 SampleVO
* @return void형
* @exception Exception
*/
public void updateBoard(BoardVO vo) throws Exception {
update("boardDAO.updateBoard", vo);
}
/**
* 글을 삭제한다.
* @param vo - 삭제할 정보가 담긴 SampleVO
* @return void형
* @exception Exception
*/
public void deleteBoard(BoardVO vo) throws Exception {
delete("boardDAO.deleteBoard", vo);
}
/**
* 글을 조회한다.
* @param vo - 조회할 정보가 담긴 SampleVO
* @return 조회한 글
* @exception Exception
*/
public BoardVO selectBoard(BoardVO vo) throws Exception {
return (BoardVO) select("boardDAO.selectBoard", vo);
}
/**
* 글 목록을 조회한다.
* @param searchMap - 조회할 정보가 담긴 Map
* @return 글 목록
* @exception Exception
*/
public List<?> selectBoardList(BoardDefaultVO searchVO) throws Exception {
return list("boardDAO.selectBoardList", searchVO);
}
/**
* 글 총 갯수를 조회한다.
* @param searchMap - 조회할 정보가 담긴 Map
* @return 글 총 갯수
* @exception
*/
public int selectBoardListTotCnt(BoardDefaultVO searchVO) {
return (Integer) select("boardDAO.selectBoardListTotCnt", searchVO);
}
}
BoardMapper.java
/*
* Copyright 2011 MOPAS(Ministry of Public Administration and Security).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package egovframework.example.board.service.impl;
import java.util.List;
import egovframework.example.board.service.BoardDefaultVO;
import egovframework.example.board.service.BoardVO;
import egovframework.rte.psl.dataaccess.mapper.Mapper;
/**
* Board에 관한 데이터처리 매퍼 클래스
*
* @author 표준프레임워크센터
* @since 2014.01.24
* @version 1.0
* @see <pre>
* == 개정이력(Modification Information) ==
*
* 수정일 수정자 수정내용
* ---------------- ------------ ---------------------------
* 2014.01.24 표준프레임워크센터 최초 생성
*
* </pre>
*/
@Mapper("boardMapper")
public interface BoardMapper {
/**
* 글을 등록한다.
* @param vo - 등록할 정보가 담긴 BoardVO
* @return 등록 결과
* @exception Exception
*/
void insertBoard(BoardVO vo) throws Exception;
/**
* 글을 수정한다.
* @param vo - 수정할 정보가 담긴 BoardVO
* @return void형
* @exception Exception
*/
void updateBoard(BoardVO vo) throws Exception;
/**
* 글을 삭제한다.
* @param vo - 삭제할 정보가 담긴 BoardVO
* @return void형
* @exception Exception
*/
void deleteBoard(BoardVO vo) throws Exception;
/**
* 글을 조회한다.
* @param vo - 조회할 정보가 담긴 BoardVO
* @return 조회한 글
* @exception Exception
*/
BoardVO selectBoard(BoardVO vo) throws Exception;
/**
* 글 목록을 조회한다.
* @param searchVO - 조회할 정보가 담긴 VO
* @return 글 목록
* @exception Exception
*/
List<?> selectBoardList(BoardDefaultVO searchVO) throws Exception;
/**
* 글 총 갯수를 조회한다.
* @param searchVO - 조회할 정보가 담긴 VO
* @return 글 총 갯수
* @exception
*/
int selectBoardListTotCnt(BoardDefaultVO searchVO);
}
BoardServiceImpl.java
/*
* Copyright 2008-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package egovframework.example.board.service.impl;
import java.util.List;
import egovframework.example.board.service.BoardDefaultVO;
import egovframework.example.board.service.BoardService;
import egovframework.example.board.service.BoardVO;
import egovframework.example.sample.service.EgovSampleService;
import egovframework.example.sample.service.SampleDefaultVO;
import egovframework.example.sample.service.SampleVO;
import egovframework.rte.fdl.cmmn.EgovAbstractServiceImpl;
import egovframework.rte.fdl.idgnr.EgovIdGnrService;
import javax.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
/**
* @Class Name : EgovSampleServiceImpl.java
* @Description : Sample Business Implement Class
* @Modification Information
* @
* @ 수정일 수정자 수정내용
* @ --------- --------- -------------------------------
* @ 2009.03.16 최초생성
*
* @author 개발프레임웍크 실행환경 개발팀
* @since 2009. 03.16
* @version 1.0
* @see
*
* Copyright (C) by MOPAS All right reserved.
*/
@Service("boardService")
public class BoardServiceImpl extends EgovAbstractServiceImpl implements BoardService {
private static final Logger LOGGER = LoggerFactory.getLogger(BoardServiceImpl.class);
/** SampleDAO */
// TODO ibatis 사용
@Resource(name = "boardDAO")
private BoardDAO boardDAO;
// TODO mybatis 사용
// @Resource(name="sampleMapper")
// private SampleMapper sampleDAO;
/** ID Generation */
@Resource(name = "egovIdGnrService")
private EgovIdGnrService egovIdGnrService;
/**
* 글을 등록한다.
* @param vo - 등록할 정보가 담긴 SampleVO
* @return 등록 결과
* @exception Exception
*/
@Override
public String insertBoard(BoardVO vo) throws Exception {
LOGGER.debug(vo.toString());
/** ID Generation Service */
String idx = egovIdGnrService.getNextStringId();
vo.setIdx(idx);
LOGGER.debug(vo.toString());
boardDAO.insertBoard(vo);
return idx;
}
/**
* 글을 수정한다.
* @param vo - 수정할 정보가 담긴 SampleVO
* @return void형
* @exception Exception
*/
@Override
public void updateBoard(BoardVO vo) throws Exception {
boardDAO.updateBoard(vo);
}
/**
* 글을 삭제한다.
* @param vo - 삭제할 정보가 담긴 SampleVO
* @return void형
* @exception Exception
*/
@Override
public void deleteBoard(BoardVO vo) throws Exception {
boardDAO.deleteBoard(vo);
}
/**
* 글을 조회한다.
* @param vo - 조회할 정보가 담긴 SampleVO
* @return 조회한 글
* @exception Exception
*/
@Override
public BoardVO selectBoard(BoardVO vo) throws Exception {
BoardVO resultVO = boardDAO.selectBoard(vo);
if (resultVO == null)
throw processException("info.nodata.msg");
return resultVO;
}
/**
* 글 목록을 조회한다.
* @param searchVO - 조회할 정보가 담긴 VO
* @return 글 목록
* @exception Exception
*/
@Override
public List<?> selectBoardList(BoardDefaultVO searchVO) throws Exception {
return boardDAO.selectBoardList(searchVO);
}
/**
* 글 총 갯수를 조회한다.
* @param searchVO - 조회할 정보가 담긴 VO
* @return 글 총 갯수
* @exception
*/
@Override
public int selectBoardListTotCnt(BoardDefaultVO searchVO) {
return boardDAO.selectBoardListTotCnt(searchVO);
}
}
BoardDefaultVO.java
/*
* Copyright 2008-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package egovframework.example.board.service;
import java.io.Serializable;
import org.apache.commons.lang3.builder.ToStringBuilder;
/**
* @Class Name : SampleDefaultVO.java
* @Description : SampleDefaultVO Class
* @Modification Information
* @
* @ 수정일 수정자 수정내용
* @ --------- --------- -------------------------------
* @ 2009.03.16 최초생성
*
* @author 개발프레임웍크 실행환경 개발팀
* @since 2009. 03.16
* @version 1.0
* @see
*
* Copyright (C) by MOPAS All right reserved.
*/
public class BoardDefaultVO implements Serializable {
/**
* serialVersion UID
*/
private static final long serialVersionUID = -858838578081269359L;
/** 검색조건 */
private String searchCondition = "";
/** 검색Keyword */
private String searchKeyword = "";
/** 검색사용여부 */
private String searchUseYn = "";
/** 현재페이지 */
private int pageIndex = 1;
/** 페이지갯수 */
private int pageUnit = 10;
/** 페이지사이즈 */
private int pageSize = 10;
/** firstIndex */
private int firstIndex = 1;
/** lastIndex */
private int lastIndex = 1;
/** recordCountPerPage */
private int recordCountPerPage = 10;
public int getFirstIndex() {
return firstIndex;
}
public void setFirstIndex(int firstIndex) {
this.firstIndex = firstIndex;
}
public int getLastIndex() {
return lastIndex;
}
public void setLastIndex(int lastIndex) {
this.lastIndex = lastIndex;
}
public int getRecordCountPerPage() {
return recordCountPerPage;
}
public void setRecordCountPerPage(int recordCountPerPage) {
this.recordCountPerPage = recordCountPerPage;
}
public String getSearchCondition() {
return searchCondition;
}
public void setSearchCondition(String searchCondition) {
this.searchCondition = searchCondition;
}
public String getSearchKeyword() {
return searchKeyword;
}
public void setSearchKeyword(String searchKeyword) {
this.searchKeyword = searchKeyword;
}
public String getSearchUseYn() {
return searchUseYn;
}
public void setSearchUseYn(String searchUseYn) {
this.searchUseYn = searchUseYn;
}
public int getPageIndex() {
return pageIndex;
}
public void setPageIndex(int pageIndex) {
this.pageIndex = pageIndex;
}
public int getPageUnit() {
return pageUnit;
}
public void setPageUnit(int pageUnit) {
this.pageUnit = pageUnit;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
}
}
BoardService.java
/*
* Copyright 2008-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package egovframework.example.board.service;
import java.util.List;
/**
* @Class Name : EgovSampleService.java
* @Description : EgovSampleService Class
* @Modification Information
* @
* @ 수정일 수정자 수정내용
* @ --------- --------- -------------------------------
* @ 2009.03.16 최초생성
*
* @author 개발프레임웍크 실행환경 개발팀
* @since 2009. 03.16
* @version 1.0
* @see
*
* Copyright (C) by MOPAS All right reserved.
*/
public interface BoardService {
/**
* 글을 등록한다.
* @param vo - 등록할 정보가 담긴 SampleVO
* @return 등록 결과
* @exception Exception
*/
String insertBoard(BoardVO vo) throws Exception;
/**
* 글을 수정한다.
* @param vo - 수정할 정보가 담긴 SampleVO
* @return void형
* @exception Exception
*/
void updateBoard(BoardVO vo) throws Exception;
/**
* 글을 삭제한다.
* @param vo - 삭제할 정보가 담긴 SampleVO
* @return void형
* @exception Exception
*/
void deleteBoard(BoardVO vo) throws Exception;
/**
* 글을 조회한다.
* @param vo - 조회할 정보가 담긴 SampleVO
* @return 조회한 글
* @exception Exception
*/
BoardVO selectBoard(BoardVO vo) throws Exception;
/**
* 글 목록을 조회한다.
* @param searchVO - 조회할 정보가 담긴 VO
* @return 글 목록
* @exception Exception
*/
List<?> selectBoardList(BoardDefaultVO searchVO) throws Exception;
/**
* 글 총 갯수를 조회한다.
* @param searchVO - 조회할 정보가 담긴 VO
* @return 글 총 갯수
* @exception
*/
int selectBoardListTotCnt(BoardDefaultVO searchVO);
}
BoardVO.java
/*
* Copyright 2008-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package egovframework.example.board.service;
/**
* @Class Name : BoardVO.java
* @Description : BoardVO Class
* @Modification Information
* @
* @ 수정일 수정자 수정내용
* @ --------- --------- -------------------------------
* @ 2009.03.16 최초생성
*
* @author 개발프레임웍크 실행환경 개발팀
* @since 2009. 03.16
* @version 1.0
* @see
*
* Copyright (C) by MOPAS All right reserved.
*/
public class BoardVO extends BoardDefaultVO {
private static final long serialVersionUID = 1L;
/** 아이디 */
private String idx;
/** 제목 */
private String subject;
/** 내용 */
private String contents;
/** 조회수 */
private String count;
/** 등록자 */
private String write;
/** 등록자 이름 */
private String writeNm;
/** 등록일 **/
private String indate;
/** 댓글 **/
/** 번호 */
private String seq;
/** 내용 */
private String reply;
/** 파일 이름 **/
private String filename;
public String getIdx() {
return idx;
}
public void setIdx(String idx) {
this.idx = idx;
}
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
public String getContents() {
return contents;
}
public void setContents(String contents) {
this.contents = contents;
}
public String getCount() {
return count;
}
public void setCount(String count) {
this.count = count;
}
public String getWrite() {
return write;
}
public void setWrite(String write) {
this.write = write;
}
public String getWriteNm() {
return writeNm;
}
public void setWriteNm(String writeNm) {
this.writeNm = writeNm;
}
public String getIndate() {
return indate;
}
public void setIndate(String indate) {
this.indate = indate;
}
public String getSeq() {
return seq;
}
public void setSeq(String seq) {
this.seq = seq;
}
public String getReply() {
return reply;
}
public void setReply(String reply) {
this.reply = reply;
}
public String getFilename() {
return filename;
}
public void setFilename(String filename) {
this.filename = filename;
}
}
728x90
반응형
'eGovFramework > egovframework' 카테고리의 다른 글
전자정부프레임워크 게시판 기본(3) (0) | 2020.12.22 |
---|---|
전자정부프레임워크 게시판 기본(2) (0) | 2020.12.22 |
전자정부프레임워크 게시판 기본(1) (0) | 2020.12.21 |
전자정부프레임워크(eGovFramework) 샘플 게시판 (0) | 2020.12.21 |