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
- java.sql.SQLRecoverableException
- OpenAPI
- Law of Demeter
- 클린코드
- avax.net.ssl.SSLHandshakeException:
- 디미터 법칙
- 프로토타입 모형
- was SQLRecoverableException
- plsql
- 폭포수 모형
- Bandit Level 6
- vue
- pl/sql
- springboot
- 명령어공부
- 변수명 짓는법
- Bandit Level 5
- was버그
- CSS
- mysql 튜닝
- 인증서만료에러
- 시스템 파악
- Bandit Level 6 → Level 7
- table scan
- 에자일 모형
- 시스템 파악 정리
- 스크럼기법
- SQLRecoverableException
- 커맨드공부
- 나선형 모형
Archives
- Today
- Total
개발햄비
[java] springBoot + mybatis + mysql 게시판 추가,삭제,갱신 기능 본문
1. 게시판 추가 , 삭제, 갱신 기능 넣기
** 1. boardController 추가**
package com.example.demo.controller;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import com.example.demo.bean.BoardData;
import com.example.demo.service.BoardService;
@Controller
public class BoardController {
@Resource(name="com.example.demo.service.BoardService")
BoardService boardService;
// get boardList
@RequestMapping("/boardList")
private String boardList(Model model) throws Exception{
model.addAttribute("boardList", boardService.getBoardList());
return "boardList";
}
// get boardDetail
@RequestMapping("/boardDetail/{boardNum}")
private String boardDetail(@PathVariable int boardNum, Model model) throws Exception{
model.addAttribute("boardDetail", boardService.getBoardDetail(boardNum));
return "boardDetail";
}
@RequestMapping("/insert") //게시글 작성폼 호출
private String boardInsertForm(){
return "insert";
}
@RequestMapping("/insertProc")
private String boardInsertProc(HttpServletRequest request) throws Exception{
BoardData board = new BoardData();
boardService.boardInsert(board);
return "redirect:/boardList";
}
@RequestMapping("/update/{boardNum}") //게시글 수정폼 호출
private String boardUpdateForm(@PathVariable int boardNum, Model model) throws Exception{
model.addAttribute("boardDetail", boardService.getBoardDetail(boardNum));
return "update";
}
@RequestMapping("/updateProc")
private void boardUpdateProc(HttpServletRequest request) throws Exception{
BoardData board = new BoardData();
boardService.boardUpdate(board);
}
@RequestMapping("/delete/{boardNum}")
private String boardDelete(@PathVariable int boardNum) throws Exception{
boardService.boardDelete(boardNum);
return "redirect:/boardList";
}
}
* retrun type이 int가 아닌 void로 수정해주세요
*에러 클릭후 create method 'boardUpdate(BoardData)'를 누르면 자동으로 메소드가 생성됩니다.
** 2.boardService 추가**
*자동으로 생성하면 위와 같이 코드가 생성됩니다. TODO 부분을 아래와 같이 코드를 넣어줍니다
** 3.boardMapper.java 추가**
*위와 같이 다시 에러를 클릭하여 메소드 자동생성을 해줍니다
*자동생성 헀다면 위와 같이 코드가 생깁니다.
** 4. boardMapper.xml 추가**
boardMapper.java의 메소드 명과 id를 통해서 매핑을 해줍시다.
** 5. insert.jsp, update.jsp 추가**
** 6. 데이터 통신 확인**
http://localhost:8080/update/1
불러오는 중입니다...
불러오는 중입니다...
2. 게시글 작성 페이지 디자인 하기
- bootStrap.jsp작성
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- jQuery -->
<script src="//code.jquery.com/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<!-- BootStrap theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap-theme.min.css">
- insert.jsp 편집
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert Form</title>
</head>
<body>
<h2> Create Board Info </h2>
<div class="container">
<form action="/insertProc" method="post">
<div class="form-group">
<label for="subject">title</label>
<input type="text" class="form-control" id="subject" name="subject" placeholder="제목을 입력하세요.">
</div>
<div class="form-group">
<label for="writer">writer</label>
<input type="text" class="form-control" id="writer" name="writer" placeholder="내용을 입력하세요.">
</div>
<div class="form-group">
<label for=content">content</label>
<textarea class="form-control" id="content" name="content" rows="3"></textarea>
</div>
<button type="submit" class="btn btn-primary">OK</button>
</form>
</div>
<%@ include file="bootstrap.jsp" %>
</body>
</html>
-
boardController.java 편집
@RequestMapping("/insertProc")
private String boardInsertProc(HttpServletRequest request) throws Exception{
BoardData board = new BoardData();
board.setSubject(request.getParameter("subject"));
board.setWriter(request.getParameter("writer"));
board.setContent(request.getParameter("content"));
boardService.boardInsert(board);
return "redirect:/boardList";
}
3. 게시글 작성 데이터 확인
'개발 > java' 카테고리의 다른 글
[java]HashMap과 HashTable차이 (0) | 2021.04.18 |
---|---|
[java] springBoot + mybatis + mysql 게시판 read기능 (0) | 2019.10.27 |
[java] springBoot + mybatis + mysql 게시판 환경설정(2) (0) | 2019.10.24 |
[java] springBoot + mybatis + mysql 게시판 환경설정(1) (0) | 2019.10.23 |
[자료구조] java stack 구현하기 (2) (0) | 2019.03.10 |