티스토리 뷰
1. 게시판 글 내용 수정하기
1) Controller
// 5. Modify부분 처리
@RequestMapping(method = RequestMethod.POST,value = "/modify")
public String modify(HttpServletRequest request,Model model) {
System.out.println("modify()");
model.addAttribute("request",request);
command = new BModifyCommand();
command.execute(model);
return "redirect:list";
}
2) Command
package com.javalec.spring_pjt_board_command;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.ui.Model;
import com.javalec.spring_pjt_board_dao.BDao;
public class BModifyCommand implements BCommand {
@Override
public void execute(Model model) {
// TODO Auto-generated method stub
Map<String, Object> map = model.asMap();
HttpServletRequest request = (HttpServletRequest) map.get("request");
String bId = request.getParameter("bId");
String bName = request.getParameter("bName");
String bTitle = request.getParameter("bTitle");
String bContent = request.getParameter("bContent");
BDao dao = new BDao();
dao.modify(bId,bName,bTitle,bContent);
}
}
3) DAO
public void modify(String bId, String bName, String bTitle, String bContent) {
Connection connection = null;
PreparedStatement preparedStatement =null;
try {
connection = dataSource.getConnection();
// 쿼리문 순서대로 setString 순서 결정 된다.
String query ="update mvc_board set bName = ?,bTitle = ?, bContent = ? where bId = ?";
preparedStatement = connection.prepareStatement(query);
preparedStatement.setString(1,bName);
preparedStatement.setString(2,bTitle);
preparedStatement.setString(3,bContent);
preparedStatement.setInt(4,Integer.parseInt(bId));
//반환형이int형 이므로
int rn = preparedStatement.executeUpdate();
}catch(Exception e) {
}finally {
try {
if(preparedStatement != null) {
preparedStatement.close();
}
if(connection != null) {
connection.close();
}
}catch(Exception e) {
e.printStackTrace();
}
}
4) DTO
import java.sql.Timestamp;
// Database의 데이터->객체로 바꿔주는 부분
public class BDto {
int bId;
String bName;
String bTitle;
String bContent;
Timestamp bDate;
int bHit;
int bGroup;
int bStep;
int bIndent;
// 파라미터 없는 Structure
public BDto() {
// TODO Auto-generated constructor stub
}
// 파라미터 있는 Structrue
public BDto(int bId,String bName,String bTitle,String bContent,Timestamp bDate,int bHit,int bGroup,
int bStep,int bIndent) {
// TODO Auto-generated constructor stub
this.bId = bId;
this.bName = bName;
this.bTitle = bTitle;
this.bDate = bDate;
this.bContent = bContent;
this.bHit = bHit;
this.bGroup = bGroup;
this.bStep = bStep;
this.bIndent = bIndent;
}
public int getbId() {
return bId;
}
public void setbId(int bId) {
this.bId = bId;
}
public String getbName() {
return bName;
}
public void setbName(String bName) {
this.bName = bName;
}
public String getbTitle() {
return bTitle;
}
public void setbTitle(String bTitle) {
this.bTitle = bTitle;
}
public String getbContent() {
return bContent;
}
public void setbContent(String bContent) {
this.bContent = bContent;
}
public Timestamp getbDate() {
return bDate;
}
public void setbDate(Timestamp bDate) {
this.bDate = bDate;
}
public int getbHit() {
return bHit;
}
public void setbHit(int bHit) {
this.bHit = bHit;
}
public int getbGroup() {
return bGroup;
}
public void setbGroup(int bGroup) {
this.bGroup = bGroup;
}
public int getbStep() {
return bStep;
}
public void setbStep(int bStep) {
this.bStep = bStep;
}
public int getbIndent() {
return bIndent;
}
public void setbIndent(int bIndent) {
this.bIndent = bIndent;
}
}
'Spring' 카테고리의 다른 글
[Spring] MVC - 게시판 만들기 7(게시판 응답하기) (0) | 2018.03.15 |
---|---|
[Spring] MVC - 게시판 만들기 6(게시판 글 삭제하기) (0) | 2018.03.15 |
[Spring] MVC - 게시판 만들기 4(글 내용 보기) (0) | 2018.03.15 |
[Spring] mysql DateTime Type Error (0) | 2018.03.14 |
[Spring] Mysql 한글 깨짐 UTF-8 인코딩 해결하기 (2) | 2018.03.14 |
- Total
- Today
- Yesterday
- Algorigm
- node
- 리버싱
- 백준
- 백준알고리즘
- 초보자를 위한 C언어 300제
- C langauge
- Spring
- db
- 감자개발자
- 알고리즘
- Controller
- 노드
- 텐서플로우
- Android
- 프로그래밍
- 스프링
- 학교
- node.js
- 머신러닝
- MVC
- 감자코딩
- 코드엔진
- 안드로이드
- TensorFlow
- C언어
- 복습
- BFS
- programming
- 개발하는 관광이
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |