ProductCont.java
@RequestMapping("/delete")
public String delete(int product_code, HttpServletRequest req) {
String filename = productDao.filename(product_code);
if(filename != null && !filename.equals("-")) {
ServletContext application = req.getSession().getServletContext();
String path = application.getRealPath("/storage");
File file = new File(path+"\\"+filename);
if(file.exists()) {
file.delete();
}//if end
}//if end
productDao.delete(product_code);
return "redirect:/product/list";
}//delete() end
ProductDAO.java
public String filename(int product_code) {
return sqlSession.selectOne("product.filename", product_code);
}//filename() end
public void delete(int product_code) {
sqlSession.delete("product.delete", product_code);
}//delete() end
product.xml
<select id="filename" resultType="String">
SELECT filename
FROM product
WHERE product_code=#{product_code}
</select>
<delete id="delete">
DELETE FROM product
WHERE product_code=#{product_code}
</delete>
'웹개발 교육 > Spring' 카테고리의 다른 글
[77일] Spring (25) - MyBatis 프로젝트 (댓글 게시판-목록, 삭제, 수정) (0) | 2022.11.15 |
---|---|
[76일] Spring (24) - MyBatis 프로젝트 (댓글 게시판) (0) | 2022.11.14 |
[75일] Spring (22) - MyBatis 프로젝트 (수정) (0) | 2022.11.11 |
[75일] Spring (21) - MyBatis 프로젝트 (상세보기) (0) | 2022.11.11 |
[75일] Spring (20) - MyBatis 프로젝트 (검색) (0) | 2022.11.11 |