Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- autoset
- 네트워크관리사
- php
- 자바
- 이것이 자바다
- rinux
- ospf
- 라우터
- 네트워크
- 버추얼머신
- javaee
- VLAN
- 원형그래프
- 오라클
- jsp연결
- Java
- Cisco
- w3school
- cisco packet
- 참조타입
- 데이터베이스
- html
- NCS
- jsp
- 리눅스
- ciscopacket
- sql
- Oracle
- 정처기필기
- 정보처리기사
Archives
- Today
- Total
기록해! 정리해!
비즈니스 컴포넌트 실습 1 - Board 코드 본문
BoardDao
package com.springbook.biz.board;
import java.util.List;
public interface BoardDao {
void insert(BoardVO vo);
List<BoardVO> select();
void delete(int seq);
BoardVO edit(int seq);
}
BoardService
package com.springbook.biz.board;
import java.util.List;
public interface BoardService {
void insert(BoardVO vo);
List<BoardVO> select();
void delete(int seq);
BoardVO edit(int seq);
}
BoardInsertClient
package com.springbook.biz.board;
import java.util.List;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;
public class BoardInsertClient {
public static void main(String[] args) {
AbstractApplicationContext container =
new GenericXmlApplicationContext("applicationContext.xml");
BoardService service=(BoardService)container.getBean("boardService"); // SamSungTV , LgTV
BoardVO vo = new BoardVO();
vo.setTitle("임시제목2");
vo.setWriter("홍길동2");
vo.setContent("임시내용2 ......");
service.insert(vo);
List<BoardVO> li = service.select();
for(int i=0 ; i < li.size() ; i++ ) {
BoardVO m = li.get(i);
System.out.println(m.toString());
}
container.close();
}
}
BoardServiceImpl
package com.springbook.biz.board.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.springbook.biz.board.BoardDao;
import com.springbook.biz.board.BoardService;
import com.springbook.biz.board.BoardVO;
@Service("boardService")
public class BoardServiceImpl implements BoardService {
BoardServiceImpl(){
System.out.println("===> BoardServiceImpl 생성자");
}
@Autowired
private BoardDao dao ;
@Override
public void insert(BoardVO vo) {
dao.insert(vo);
}
@Override
public List<BoardVO> select() {
return dao.select();
}
@Override
public void delete(int seq) {
dao.delete(seq);
}
@Override
public BoardVO edit(int seq) {
return dao.edit(seq);
}
}
BoardDaoImpl
package com.springbook.biz.board.impl;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import org.springframework.stereotype.Repository;
import com.springbook.biz.board.BoardDao;
import com.springbook.biz.board.BoardVO;
import com.springbook.biz.common.JDBCUtil;
@Repository("boardDao")
public class BoardDaoImpl implements BoardDao {
private JDBCUtil jDBCUtil =null;
private Connection conn = null;
private PreparedStatement pstmt=null;
private ResultSet rs =null;
private final String BOARD_INSERT="insert into board(seq, title, writer, content, REGDATE)"
+ " values( (select nvl(max(seq)+1,0) from board) ,?,?,?,'2022-08-25')";
private final String BOARD_SELECT="select seq, title, writer, content, REGDATE, cnt from board ";
private final String BOARD_DELETE="delete from board where seq=? ";
private final String BOARD_EDIT="select seq, title, writer, content, REGDATE, cnt from board where seq=? ";
BoardDaoImpl(){
System.out.println("===>BoardDaoImpl 생성자 ");
jDBCUtil = JDBCUtil.getInstance();
}
@Override
public void insert(BoardVO vo) {
try {
conn = jDBCUtil.getConnection();
pstmt = conn.prepareStatement(BOARD_INSERT);
pstmt.setString(1, vo.getTitle());
pstmt.setString(2, vo.getWriter());
pstmt.setString(3, vo.getContent());
pstmt.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
jDBCUtil.close(pstmt, conn);
}
}
@Override
public List<BoardVO> select() {
List<BoardVO> li = new ArrayList<BoardVO>();
try {
conn = jDBCUtil.getConnection();
pstmt = conn.prepareStatement(BOARD_SELECT);
rs=pstmt.executeQuery();
while(rs.next()) {
BoardVO vo = new BoardVO();
vo.setSeq(rs.getInt("seq"));
vo.setTitle(rs.getString("title"));
vo.setWriter(rs.getString("writer"));
vo.setContent(rs.getString("content"));
vo.setRegDate(rs.getDate("regDate"));
vo.setCnt(rs.getInt("cnt"));
li.add(vo);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
jDBCUtil.close(rs, pstmt, conn);
}
return li;
}
@Override
public void delete(int seq) {
try {
conn = jDBCUtil.getConnection();
pstmt = conn.prepareStatement(BOARD_DELETE);
pstmt.setInt(1, seq);
pstmt.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
jDBCUtil.close(pstmt, conn);
}
}
@Override
public BoardVO edit(int seq) {
BoardVO vo = new BoardVO();
try {
conn = jDBCUtil.getConnection();
pstmt = conn.prepareStatement(BOARD_EDIT);
pstmt.setInt(1, seq);
rs=pstmt.executeQuery();
rs.next();
vo.setSeq(rs.getInt("seq"));
vo.setTitle(rs.getString("title"));
vo.setWriter(rs.getString("writer"));
vo.setContent(rs.getString("content"));
vo.setRegDate(rs.getDate("regDate"));
vo.setCnt(rs.getInt("cnt"));
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
jDBCUtil.close(rs, pstmt, conn);
}
return vo;
}
}
'Spring' 카테고리의 다른 글
카카오 API 지도 - 마크와텍스트 / 선으로 거리계산 / 여러개의마커제어 (0) | 2022.09.20 |
---|---|
오라클 드라이버 사용하기 (0) | 2022.09.20 |
비즈니스 컴포넌트 실습 1 - JDBCUtil 사용하기 (0) | 2022.09.20 |
비즈니스 컴포넌트 실습 1 - pom.xml (드라이버 내려받기) (0) | 2022.09.20 |
비즈니스 컴포넌트 실습 1 - table과 vo (0) | 2022.09.20 |
Comments