
<select id="selectBoardList" parameterType="map" resultType="Board">
select * from (select rownum rn, boardlist.* from (select * from board
<where>
<if test="sDate != null and sDate!=''">
and c_date <![CDATA[>=]]> #{sDate}
</if>
<if test="eDate!=null and eDate!=''">
and c_date <![CDATA[<=]]> #{eDate}
</if>
</where>
order by b_idx desc) boardlist ) where rn between #{startRow} and #{endRow}
</select>
<select id="selectBoardList" parameterType="map" resultType="Board">
select * from (select rownum rn, boardlist.* from (select * from board
<where>
<if test="sDate != null and sDate!=''">
and c_date <![CDATA[>=]]> #{sDate}
</if>
<if test="eDate!=null and eDate!=''">
and c_date <![CDATA[<=]]> TO_DATE(#{eDate}, 'YYYY-MM-DD')+1
</if>
</where>
order by b_idx desc) boardlist ) where rn between #{startRow} and #{endRow}
</select>
var page=1;
noticeListDisplay(page);
function noticeListDisplay(pageNum) {
page = pageNum;
const urlParams = new URLSearchParams(window.location.search);
const startValue = urlParams.get('startdate');
const endValue = urlParams.get('enddate');
$.ajax({
type: "post",
url: "${pageContext.request.contextPath}/blogList",
data: {
pageNum: pageNum,
sDate: startValue,
eDate: endValue
},
dataType: "json",
success: function(result) {
var html = "<section class='md'>";
html = "<div class='container'>";
html += "<div class='row'>";
$(result.boardList).each(function(){
html += "<div class='col-md-6 col-lg-4 mb-1-9 blog-style-one'>";
html += "<article class='item text-center'>";
html += "<div class='post-img'>";
html += "<img src='${pageContext.request.contextPath}/img/"+this.img+"' style='height: 300px; width: 400px;'>";
html += "</div>";
html += "<div class='content'>";
html += "<h3 class='h5 mb-2'><a href='${pageContext.request.contextPath}/blog/view'>"+this.title+"</a></h3>";
html += "<div class='tag alt-font'>";
html += "<span class='d-inline-block text-primary'>"+this.cdate+"</span>";
html += "</div>";
html += "</div>";
html += "</article>";
html += "</div>";
});
html += "</div>";
html += "</div>";
html += "</section>";
$("#noticetable").html(html);
pageNumDisplay(result.pager);
},
error: function(xhr, status, error) {
console.log(error);
}
});
}
function pageNumDisplay(pager) {
var html="";
if(pager.startPage > pager.blockSize) {
html+="<a href='javascript:noticeListDisplay("+pager.prevPage+")'>[이전]</a>";
}
for(i=pager.startPage;i<=pager.endPage;i++) {
if(pager.pageNum!=i) {
html+="<a href='javascript:noticeListDisplay("+i+")'>[ "+i+" ]</a>";
} else {
html+="[ "+i+" ] ";
}
}
if(pager.endPage != pager.totalPage) {
html+="<a href='javascript:noticeListDisplay("+pager.nextPage+")'>[다음]</a>";
}
$("#pageNumDiv").html(html);
}
params.get("sDate") @RequestMapping(value = "/blog", method = RequestMethod.GET)
public String blogmain() {
return "blog/main";
}
@RequestMapping(value = "/blogList", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> blogList(@RequestParam(defaultValue = "1") int pageNum, @RequestParam Map<String, Object> params) {
int totalQuestion = boardDAO.selectBoardCount(params);
int pageSize=6;
int blockSize=5;
Pager pager= new Pager(pageNum, totalQuestion, pageSize, blockSize);
Map<String, Object> pageMap = new HashMap<String, Object>();
pageMap.put("startRow", pager.getStartRow());
pageMap.put("endRow", pager.getEndRow());
pageMap.put("sDate", params.get("sDate"));
pageMap.put("eDate", params.get("eDate"));
Map<String, Object> resultMap = new HashMap<String, Object>();
List<Board> boardList = boardService.getBoardList(pageMap);
resultMap.put("boardList", boardList);
resultMap.put("pager", pager);
return resultMap;
}

<select id="selectBoardList" parameterType="map" resultType="Board">
select * from (select rownum rn, boardlist.* from (select * from board
<where>
<if test="sDate != null and sDate!=''">
and c_date <![CDATA[>=]]> #{sDate}
</if>
<if test="eDate!=null and eDate!=''">
and c_date <![CDATA[<=]]> TO_DATE(#{eDate}, 'YYYY-MM-DD')+1
</if>
<if test="keyword!=null and keyword!=''">
<bind name="keyword" value="'%'+keyword+'%'"/>
and lower(title) like lower(#{keyword})
</if>
</where>
order by b_idx desc) boardlist ) where rn between #{startRow} and #{endRow}
</select>
<!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.5</version>
</dependency>
<beans:bean class="org.springframework.web.multipart.commons.CommonsMultipartResolver" id="multipartResolver">
<!-- maxUploadSize 필드에 최대 업로드 파일의 제한 용량(Byte)을 주입 -->
<beans:property name="maxUploadSize" value="20971520"/>
<!-- defaultEncoding 필드에 전달값에 대한 문자형태(캐릭터셋)을 주입 -->
<beans:property name="defaultEncoding" value="utf-8"/>
</beans:bean>
//디렉토리의 시스템 경로를 위해 ServletContext 객체 의존성 주입
private final WebApplicationContext context;
//파일 업로드하여 삽입 후 업로드 이름으로 이미지 이름 변경
@RequestMapping(value = "/upload", method = RequestMethod.POST)
public String upload(@RequestParam MultipartFile uploadFile, Model model, @ModelAttribute Board board) throws BoardNotFoundException, IOException {
//시스템경로 반환받아 저장
String uploadDirectory=context.getServletContext().getRealPath("/resources/img");
String originalFilename=uploadFile.getOriginalFilename();
//파일객체 생성해서 전달파일을 서버 디렉토리에 저장
File file=new File(uploadDirectory, originalFilename);
String uploadFilename=originalFilename;
//파일이 이미 존재한다면 번호를 부여해서 이름을 변경 후 저장
int i=0;
while(file.exists()) {
i++;
int index=originalFilename.lastIndexOf(".");
uploadFilename=originalFilename.substring(0, index)+"_"+i+originalFilename.substring(index);
file=new File(uploadDirectory, uploadFilename);
}
//MultipartFile 객체에 저장된 파일정보를 File 객체에 저장된 파일정보로 전달하여 저장
uploadFile.transferTo(file);
model.addAttribute("originalFilename", originalFilename);
model.addAttribute("uploadFilename", uploadFilename);
boardService.addBoard(board);
Board boardinfo=boardService.getBoard(board.getBidx());
boardinfo.setImg(uploadFilename);
boardService.modifyBoard(boardinfo);
return "redirect:/blog";
}
<input type="file" name="uploadFile" id="img">

@RequestMapping(value = "/view", method = RequestMethod.GET)
public String blogview(@RequestParam int bidx, Model model) throws BoardNotFoundException, HewonNotFoundException {
Board board= boardService.getBoard(bidx);
board.setCnt(board.getCnt()+1);//조회할때마다 조회수 1씩 증가
boardService.modifyBoard(board);
model.addAttribute("boardview", board);
//작성자 이름출력을 위해 회원정보를 속성값으로 저장
model.addAttribute("hewoninfo", hewonService.getHewon(boardService.getBoard(bidx).getBhid()));
return "blog/view";
}
@RequestMapping(value = "/view", method = RequestMethod.GET)
public String blogview(@RequestParam int bidx, Model model) throws BoardNotFoundException, HewonNotFoundException {
boardDAO.updateBoardcount(bidx);
model.addAttribute("boardview", boardService.getBoard(bidx));
model.addAttribute("hewoninfo", hewonService.getHewon(boardService.getBoard(bidx).getBhid()));
return "blog/view";
}