@RequestMapping(value = "insert", method=RequestMethod.GET)
public String insert() {
return "insform";
}
@RequestMapping(value = "insert", method=RequestMethod.POST)
public String insertSubmit(BoardBean bean) {
boolean b = boardDao.insertData(bean);
if(b) return "redirect:/list";
//err.jsp가 아닌 컨트롤러의 err으로 요청명으로써 작동했다.
else return "err";
}
..//err Controller.java
@RequestMapping("err")
public String errProcess() {
return "error";
}
..//error jsp
<body>
에러
<a href="list">글 목록으로</a>
<form action="/search" method="post">
검색대상 :
<select name="searchName">
<option value="author" selected>작성자</option>
<option value="title">제목</option>
</select>
<input type="text" name="searchValue">
<input type="submit" value="검색">
</form>
검색키워드와 카테고리를 파라미터로 넘겨받아 sql에 적용했다.
@RequestMapping(value="/search")
public String search(BoardBean bean,Model model) {
ArrayList<Board> slist = boardDao.search(bean.getSearchName(),bean.getSearchValue());
model.addAttribute("list",slist);
return "list";
}
public ArrayList<Board> search(String searchName, String searchValue) {
ArrayList<Board> list = new ArrayList<Board>();
try {
String sql = "select * from springboard";
sql += " where " + searchName + " like '%" + searchValue + "%'";
sql += " order by num desc";
public Board detail(String num) {
mappingInterface.updateReadcnt(num);// 조회수 증가
Board board = mappingInterface.selectOne(num);
return board;
}
쿼리는 조회수증가는 아래와 같다
update springboard set readcnt=readcnt+1 where num=#{num}