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
- cisco packet
- w3school
- ciscopacket
- 오라클
- NCS
- 정보처리기사
- autoset
- rinux
- html
- 정처기필기
- 네트워크
- ospf
- 데이터베이스
- jsp
- Cisco
- php
- Java
- VLAN
- sql
- 이것이 자바다
- 리눅스
- 자바
- jsp연결
- 라우터
- Oracle
- javaee
- 참조타입
- 원형그래프
- 네트워크관리사
- 버추얼머신
Archives
- Today
- Total
기록해! 정리해!
비즈니스 컴포넌트 실습 I (복습) - Board 본문
BoardService
package com.springbook.biz.board;
import java.util.List;
public interface BoardService {
void insert(BoardVo vo);
void update(BoardVo vo);
void delete(int seq);
BoardVo edit(int seq);
List<BoardVo> selectAll();
}
BoardDao
package com.springbook.biz.board;
import java.util.List;
public interface BoardDao {
void insert(BoardVo vo);
void update(BoardVo vo);
void delete(int seq);
BoardVo edit(int seq);
List<BoardVo> selectAll();
}
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
public class BoardDaoImpl implements BoardDao {
BoardDaoImpl(){
dbConn = JDBCUtil.getInstance();
}
private JDBCUtil dbConn =null;
private Connection conn =null;
private PreparedStatement pstmt =null;
private ResultSet rs=null;
String BOARD_INSERT="insert into board(seq, title, writer, content)"
+ " values((select nvl(max(seq),0)+1 from board), ?,?,?)";
String BOARD_SELECT=" select seq, title, writer, content from board " ;
@Override
public void insert(BoardVo vo) {
try {
conn =dbConn.getConnection();
pstmt=conn.prepareStatement(BOARD_INSERT);
pstmt.setString(1, vo.getTitle());
pstmt.setString(2, vo.getWriter());
pstmt.setString(3, vo.getContent());
pstmt.executeUpdate();
}catch(Exception e) {
e.printStackTrace();
}finally {
dbConn.close(pstmt, conn);
}
}
@Override
public void update(BoardVo vo) {
// TODO Auto-generated method stub
}
@Override
public void delete(int seq) {
// TODO Auto-generated method stub
}
@Override
public BoardVo edit(int seq) {
// TODO Auto-generated method stub
return null;
}
@Override
public List<BoardVo> selectAll() {
List<BoardVo> li = new ArrayList<BoardVo>();
try {
conn =dbConn.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"));
li.add(vo);
}
}catch(Exception e) {
e.printStackTrace();
}finally {
dbConn.close(rs, pstmt, conn);
}
return li;
}
}
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 {
@Autowired
private BoardDao boardDao;
@Override
public void insert(BoardVo vo) {
boardDao.insert(vo);
}
@Override
public void update(BoardVo vo) {
boardDao.update(vo);
}
@Override
public void delete(int seq) {
boardDao.delete(seq);
}
@Override
public BoardVo edit(int seq) {
return boardDao.edit(seq);
}
@Override
public List<BoardVo> selectAll() {
return boardDao.selectAll();
}
}
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");
BoardVo vo =new BoardVo();
vo.setTitle("임시 제목1");
vo.setWriter("홍길동1");
vo.setContent("임시내용1 ....");
service.insert(vo);
List<BoardVo> li =service.selectAll();
for(BoardVo m :li) {
System.out.println("===> " +m.toString());
}
container.close();
}
}
'Spring' 카테고리의 다른 글
비즈니스 컴포넌트 실습 II (0) | 2022.09.22 |
---|---|
카카오 API 지도 (2) - 데이터 연동 (0) | 2022.09.21 |
비즈니스 컴포넌트 실습 I (복습) - 데이터베이스 드라이버 , JDBCUtil, applicationContext.xml (1) | 2022.09.21 |
비즈니스 컴포넌트 실습 I (복습) - VO 만들기 (1) | 2022.09.21 |
비즈니스 컴포넌트 실습 I (복습) - pom.xml / 테이블 (1) | 2022.09.21 |
Comments