티스토리 뷰

1. 게시판 글 내용 삭제

계속 진행해왔던 부분이라 따로 많은 설명은 하지 않고 넘어 가겠습니다.

1) Controller


// 8. 삭제 부

@RequestMapping("/delete")

public String delete(HttpServletRequest request,Model model) {

System.out.println("Delete()");

model.addAttribute("request",request);

command = new BDeleteCommand();

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 BDeleteCommand 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");

// Dao 객체 생성

BDao dao = new BDao();

dao.delete(bId);


}


}

3) DAO

public void delete(String strId) {

Connection connection = null;

PreparedStatement preparedStatement = null;

try {

connection = dataSource.getConnection();

String query="delete from mvc_board where bId=?";

preparedStatement = connection.prepareStatement(query);

preparedStatement.setInt(1,Integer.parseInt(strId));

int rn = preparedStatement.executeUpdate();

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}finally {

try {

} catch (Exception e2) {

// TODO: handle exception

}

}

}

4) DTO

package com.javalec.spring_pjt_board_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;

}



}






공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/11   »
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
글 보관함