728x90
๊ฒ์ํ ๊ธ์์ฑ
๋ก๊ทธ์ธ ์ฑ๊ณต ์ ๊ฒ์ํ์ผ๋ก ์ด๋
์ผ์ชฝ ๋ฐฐ๋ ๋ฉ๋ด์์ ๊ธ์ฐ๊ธฐ๋ฅผ ์ ๋ ฅ์ ์ ๋ ฅ๊ฐ๋ฅ
@RequestMapping(value = "bbsWrite.do", method = RequestMethod.GET)
public String bbsWrite(Model model) {
logger.info("BbsController bbsWrite() " + new Date());
model.addAttribute("doc_title", "๊ธ์์ฑ");
return "bbswrite.tiles";
}
<!--๊ธ์ฐ๊ธฐ -->
<insert id="addBbs" parameterType="bit.com.a.dto.BbsParam">
INSERT INTO BBS (SEQ, ID, REF, STEP, DEPTH, TITLE, CONTENT, WDATE, DEL, READCOUNT)
VALUES( SEQ_BBS.NEXTVAL, #{id}, (SELECT NVL(MAX(REF), 0)+1 FROM BBS), 0, 0, #{title},
#{content}, SYSDATE, 0, 0)
</insert>
BbsDaoImpl - addBbs
@Override
public boolean addBbs(BbsDto dto) {
int a = session.insert(ns + "addBbs", dto);
return a>0?true:false;
}
BbsServiceImpl -addBbs
@Override
public boolean addBbs(BbsDto dto) {
// TODO Auto-generated method stub
return dao.addBbs(dto);
}
@RequestMapping(value = "bbsWriteAf.do", method = RequestMethod.POST)
public String bbsWriteAf(BbsDto bbs) {
boolean a = service.addBbs(bbs);
if(a) {
logger.info("๊ธ์ด ์ถ๊ฐ๋์์ต๋๋ค " + new Date());
return "redirect:/bbslist.do";
}
logger.info("๊ธ์ด ์ถ๊ฐ ๋์ง ์์์ต๋๋ค " + new Date());
return "redirect:/bbsWrite.do";
}
๊ฒ์ํ ๊ธ ์์
๊ธ์์ ์ ๋ํ ์ผ ํ์ด์ง์์ ์์ ๊ฐ๋ฅ
๊ฒ์ํ์์ ๊ธ ์ ๋ชฉ์ ํด๋ฆญ์ ๋ํ ์ผ ํ์ด์ง๋ก ์ด๋
๊ธ์์ ๋ฒํผ์ ๋๋ฅผ์ BbsDto ํด๋์ค ๋ณ์๋ค๋ก ํ๋ผ๋ฏธํฐ๋ฅผ ๋ฐ๋๋ค
BbsController
@RequestMapping(value = "updateBbs.do", method = RequestMethod.GET)
public String updateBbs(Model model, int seq) {
logger.info("BbsController updateBbs() " + new Date());
BbsDto dto = service.getBbs(seq);
model.addAttribute("dto", dto);
model.addAttribute("doc_title", "๊ฒ์๋ฌผ ์์ ");
return "bbsupdate.tiles";
}
@RequestMapping(value = "updateBbsAf.do", method = RequestMethod.GET)
public String updateBbsAf(Model model, BbsDto bbsdto) {
logger.info("BbsController updateBbs() " + new Date());
boolean a =service.updateBbs(bbsdto);
if(a) {
logger.info("๊ธ์ด ์์ ๋์์ต๋๋ค " + new Date());
return "redirect:/bbslist.do";
}
logger.info("๊ธ์ด ์์ ๋์ง์์์ต๋๋ค " + new Date());
return "redirect:/bbslist.do";
}
Bbs.xml
<!-- ๊ฒ์๋ฌผ์์ -->
<update id="updateBbs" parameterType="bit.com.a.dto.BbsDto">
UPDATE BBS
SET TITLE=#{title}, CONTENT=#{content}
WHERE SEQ=#{seq}
</update>
BbsDaoImpl - updateBbs
@Override
public boolean updateBbs(BbsDto dto) {
int a = session.update(ns + "updateBbs", dto);
return a>0?true:false;
}
๊ฒ์ํ ๊ธ ์ญ์
Bbs.xml
<!-- ๊ฒ์๋ฌผ์ญ์ -->
<update id="deleteBbs" parameterType="int">
UPDATE BBS
SET DEL=1
WHERE SEQ=#{seq}
</update>
BbsDaoImpl - bbsdelete
@Override
public boolean bbsdelete(int seq) {
int a = session.update(ns + "deleteBbs", seq);
return a>0?true:false;
}
BbsServiceImpl -bbsdelete
@Override
public boolean bbsdelete(int seq) {
// TODO Auto-generated method stub
return dao.bbsdelete(seq);
}
ํด๋์ค ๋ณ ์ ์ฒด ์ฝ๋
์ธํฐํ์ด์ค๋ ์ฌ๋ฆฌ์ง ์์์
BbsDaoImpl
package bit.com.a.dao.impl;
import java.util.List;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import bit.com.a.dao.BbsDao;
import bit.com.a.dto.BbsDto;
import bit.com.a.dto.BbsParam;
@Repository
public class BbsDaoImpl implements BbsDao {
@Autowired
SqlSessionTemplate session;
String ns = "Bbs.";
@Override
public List<BbsDto> getBbslist(BbsParam bbs) {
return session.selectList(ns + "bbslist", bbs);
}
@Override
public int getBbsCount(BbsParam bbs) {
return session.selectOne(ns + "getBbsCount", bbs);
}
@Override
public BbsDto getBbs(int seq) {
// TODO Auto-generated method stub
return session.selectOne(ns + "getBbs", seq);
}
@Override
public void readCount(int seq) {
session.update(ns + "readcount", seq);
}
@Override
public boolean addBbs(BbsDto dto) {
int a = session.insert(ns + "addBbs", dto);
return a>0?true:false;
}
@Override
public boolean updateBbs(BbsDto dto) {
int a = session.update(ns + "updateBbs", dto);
return a>0?true:false;
}
@Override
public boolean bbsdelete(int seq) {
int a = session.update(ns + "deleteBbs", seq);
return a>0?true:false;
}
@Override
public boolean answer(int seq, BbsDto dto) {
//ํ๋ฒํธ ์ธํ
int a = session.update( ns + "updateStep", seq );
int b = session.insert(ns + "insertAns", dto);
return a>0 && b>0?true:false;
}
}
BbsServiceImpl
package bit.com.a.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import bit.com.a.dao.BbsDao;
import bit.com.a.dto.BbsDto;
import bit.com.a.dto.BbsParam;
import bit.com.a.service.BbsService;
@Service
public class BbsServiceImpl implements BbsService {
@Autowired
BbsDao dao;
@Override
public List<BbsDto> getBbslist(BbsParam bbs) {
return dao.getBbslist(bbs);
}
@Override
public int getBbsCount(BbsParam bbs) {
return dao.getBbsCount(bbs);
}
@Override
public BbsDto getBbs(int seq) {
// TODO Auto-generated method stub
return dao.getBbs(seq);
}
@Override
public void readCount(int seq) {
dao.readCount(seq);
}
@Override
public boolean addBbs(BbsDto dto) {
// TODO Auto-generated method stub
return dao.addBbs(dto);
}
@Override
public boolean updateBbs(BbsDto dto) {
// TODO Auto-generated method stub
return dao.updateBbs(dto);
}
@Override
public boolean bbsdelete(int seq) {
// TODO Auto-generated method stub
return dao.bbsdelete(seq);
}
@Override
public boolean answer(int seq, BbsDto dto) {
// TODO Auto-generated method stub
return dao.answer(seq, dto);
}
}
BbsController
package bit.com.a.controller;
import java.util.Date;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import bit.com.a.dto.BbsDto;
import bit.com.a.dto.BbsParam;
import bit.com.a.service.BbsService;
@Controller
public class BbsController {
private static Logger logger = LoggerFactory.getLogger(BbsController.class);
@Autowired
BbsService service;
@RequestMapping(value = "bbslist.do", method = RequestMethod.GET)
public String bbslist(Model model) {
model.addAttribute("doc_title", "๊ธ๋ชฉ๋ก");
return "bbslist.tiles";
}
@ResponseBody
@RequestMapping(value = "bbslistData.do", method = RequestMethod.GET)
public List<BbsDto> bbslistData(BbsParam param) {
//๊ฒ์์ฒ๋ฆฌ
String choice = param.getChoice();
String search = param.getSearch();
int page = param.getPage();
if(choice == null) {
choice = "";
}
if(search == null) {
search = "";
}
param.setChoice(choice);
param.setSearch(search);
// paging ์ฒ๋ฆฌ
int sn = param.getPage();
int start = sn * 10 + 1; // 1 11
int end = (sn + 1) * 10; // 10 20
param.setStart(start);
param.setEnd(end);
List<BbsDto> list = service.getBbslist(param);
return list;
}
@ResponseBody
@RequestMapping(value = "bbslistCount.do", method = RequestMethod.GET)
public int bbslistCount(BbsParam param) {
int count = service.getBbsCount(param);
return count;
}
@RequestMapping(value = "bbsdetail.do", method = RequestMethod.GET)
public String bbsdetail(int seq, Model model) {
BbsDto dto = service.getBbs(seq);
service.readCount(seq);
model.addAttribute("dedto", dto);
model.addAttribute("doc_title", "๋ํ
์ผ");
return "bbsdetail.tiles";
}
@RequestMapping(value = "bbsWrite.do", method = RequestMethod.GET)
public String bbsWrite(Model model) {
logger.info("BbsController bbsWrite() " + new Date());
model.addAttribute("doc_title", "๊ธ์์ฑ");
return "bbswrite.tiles";
}
@RequestMapping(value = "bbsWriteAf.do", method = RequestMethod.POST)
public String bbsWriteAf(BbsDto bbs) {
boolean a = service.addBbs(bbs);
if(a) {
logger.info("๊ธ์ด ์ถ๊ฐ๋์์ต๋๋ค " + new Date());
return "redirect:/bbslist.do";
}
logger.info("๊ธ์ด ์ถ๊ฐ ๋์ง ์์์ต๋๋ค " + new Date());
return "redirect:/bbsWrite.do";
}
@RequestMapping(value = "updateBbs.do", method = RequestMethod.GET)
public String updateBbs(Model model, int seq) {
logger.info("BbsController updateBbs() " + new Date());
BbsDto dto = service.getBbs(seq);
model.addAttribute("dto", dto);
model.addAttribute("doc_title", "๊ฒ์๋ฌผ ์์ ");
return "bbsupdate.tiles";
}
@RequestMapping(value = "updateBbsAf.do", method = RequestMethod.GET)
public String updateBbsAf(Model model, BbsDto bbsdto) {
logger.info("BbsController updateBbs() " + new Date());
boolean a =service.updateBbs(bbsdto);
if(a) {
logger.info("๊ธ์ด ์์ ๋์์ต๋๋ค " + new Date());
return "redirect:/bbslist.do";
}
logger.info("๊ธ์ด ์์ ๋์ง์์์ต๋๋ค " + new Date());
return "redirect:/bbslist.do";
}
@RequestMapping(value = "answer.do", method = RequestMethod.GET)
public String answer(Model model, int seq) {
logger.info("BbsController answer() " + new Date());
BbsDto dto = service.getBbs(seq);
model.addAttribute("parentdto", dto);
model.addAttribute("doc_title", "๋ต๊ธ๋ฌ๊ธฐ");
return "answer.tiles";
}
@RequestMapping(value = "answerAf.do", method = RequestMethod.GET)
public String answerAf(Model model, BbsDto dto) {
logger.info("BbsController answerAf() " + new Date());
System.out.println("์ปจํธ๋กค๋ฌ ๋ต๊ธ ํ์ธ" + dto.toString());
boolean a = service.answer(dto.getSeq(), dto);
return "redirect:/bbslist.do";
}
@RequestMapping(value = "deleteBbs.do", method = RequestMethod.GET)
public String deleteBbs(int seq) {
boolean a = service.bbsdelete(seq);
if(a) {
logger.info("๊ธ์ด ์ญ์ ๋์์ต๋๋ค " + new Date());
return "redirect:/bbslist.do";
}
logger.info("๊ธ์ด ์ญ์ ๋์ง์์์ต๋๋ค " + new Date());
return "redirect:/bbslist.do";
}
}
'์คํ๋ง Spring > ๐งถ ์คํ๋ง ํ๋ ์์ํฌ Spring' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
์คํ๋ง Tiles๋ฅผ ํ์ฉํ ๊ฒ์ํ ์๋ฃ์ค ๋ง๋ค๊ธฐ (ํ์ผ ์ ๋ก๋) (0) | 2021.06.25 |
---|---|
์คํ๋ง Tiles๋ฅผ ํ์ฉํ ๊ฒ์ํ๋ง๋ค๊ธฐ (์บ๋ฆฐ๋ ์์ฑ, ์์ , ์ญ์ ) ํ์บ๋ฆฐ๋ ํ์ฉ (0) | 2021.06.25 |
Spring ํ์ผ ์ ๋ก๋ (0) | 2021.06.24 |
์คํ๋ง Tiles๋ฅผ ํ์ฉํ ๊ฒ์ํ ๋ง๋ค๊ธฐ (๊ฒ์ํ ํ์ด์ง, ๊ฒ์) (0) | 2021.06.22 |
Spring Model ๊ฐ์ฒด๋ ๋ฌด์์ผ๊น? (0) | 2021.06.22 |
๋๊ธ