|
@@ -1,29 +1,93 @@
|
|
|
package com.lemon.lifecenter.controller;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileNotFoundException;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.UUID;
|
|
|
+
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
+import org.apache.commons.io.FilenameUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
+import org.springframework.transaction.annotation.Propagation;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.FileCopyUtils;
|
|
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
|
|
|
+import com.lemon.lifecenter.common.LifeCenterConfigVO;
|
|
|
import com.lemon.lifecenter.common.LifeCenterController;
|
|
|
+import com.lemon.lifecenter.common.LifeCenterFileDownload;
|
|
|
+import com.lemon.lifecenter.common.LifeCenterFunction;
|
|
|
+import com.lemon.lifecenter.common.LifeCenterPaging;
|
|
|
import com.lemon.lifecenter.common.LifeCenterSessionController;
|
|
|
+import com.lemon.lifecenter.dto.BoardDTO;
|
|
|
+import com.lemon.lifecenter.service.BoardService;
|
|
|
|
|
|
@Controller
|
|
|
@RequestMapping("/board")
|
|
|
public class BoardController extends LifeCenterController {
|
|
|
+ private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BoardService boardService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private LifeCenterConfigVO config;
|
|
|
+
|
|
|
+ private LifeCenterPaging paging;
|
|
|
+
|
|
|
@RequestMapping("/list")
|
|
|
public ModelAndView boardList(
|
|
|
- @RequestParam(value="sData", required=false, defaultValue="") String sData,
|
|
|
- @RequestParam(value="useYn", required=false, defaultValue="") String useYn,
|
|
|
+ @RequestParam(value="searchTxt", required=false, defaultValue="") String searchTxt,
|
|
|
+ @RequestParam(value="selectState", required=false, defaultValue="") String selectState,
|
|
|
@RequestParam(value="page", required=false, defaultValue="1") int page,
|
|
|
HttpServletRequest request, HttpServletResponse response) {
|
|
|
String sesGroupIdx = LifeCenterSessionController.getSession( request, "sesGroupIdx" );
|
|
|
+ BoardDTO dto = new BoardDTO();
|
|
|
+
|
|
|
+ if (!selectState.equals("")) {
|
|
|
+ if (selectState.equals("title")) {
|
|
|
+ dto.setTitle(searchTxt);
|
|
|
+ } else if (selectState.equals("content")) {
|
|
|
+ dto.setContent(searchTxt);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ dto.setLimit( ( Integer.valueOf( page ) - 1 ) * config.pageDataSize );
|
|
|
+ dto.setLimitMax( config.pageDataSize );
|
|
|
+
|
|
|
+ List<BoardDTO> list = new ArrayList<BoardDTO>();
|
|
|
+
|
|
|
+ int total = boardService.selectNoticeBoardListCount(dto);
|
|
|
+ if (total == 0) {
|
|
|
+ } else {
|
|
|
+ list = boardService.selectNoticeBoardList(dto);
|
|
|
+ }
|
|
|
+
|
|
|
+ String param = "";
|
|
|
+ paging = LifeCenterPaging.getInstance();
|
|
|
+ paging.paging(config, total, page, param);
|
|
|
+
|
|
|
ModelAndView mv = setMV("board/list");
|
|
|
mv.addObject("sesGroupIdx", sesGroupIdx);
|
|
|
+ mv.addObject("list", list);
|
|
|
+ mv.addObject("total", total);
|
|
|
+ mv.addObject("selectState", selectState);
|
|
|
+ mv.addObject("searchTxt", searchTxt);
|
|
|
+ mv.addObject("paging", paging);
|
|
|
+ mv.addObject("page", page);
|
|
|
+ mv.addObject("pageSize", dto.getLimitMax());
|
|
|
return mv;
|
|
|
}
|
|
|
|
|
@@ -34,14 +98,70 @@ public class BoardController extends LifeCenterController {
|
|
|
}
|
|
|
|
|
|
@RequestMapping("/new/insert")
|
|
|
- public String boardNewInsert() {
|
|
|
-// @ModelAttribute("dto") final CenterInfoDTO dto
|
|
|
+ @Transactional(propagation=Propagation.REQUIRED)
|
|
|
+ public String boardNewInsert(
|
|
|
+ HttpServletRequest request, HttpServletResponse response,
|
|
|
+ @ModelAttribute("dto") final BoardDTO dto,
|
|
|
+ MultipartFile file) {
|
|
|
+
|
|
|
+ if (file.isEmpty() == false) {
|
|
|
+ UUID uuid = UUID.randomUUID();
|
|
|
+ String fileName = file.getOriginalFilename();
|
|
|
+ int fileSize = (int) file.getSize(); //단위는 byte
|
|
|
+ String ext = FilenameUtils.getExtension(fileName);
|
|
|
+ String saveFileName = uuid + "." + ext;
|
|
|
+
|
|
|
+ try {
|
|
|
+ String tempPath = "../notice-temp";
|
|
|
+ File saveFile = new File(tempPath, saveFileName);
|
|
|
+ FileCopyUtils.copy(file.getBytes(),saveFile);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ LifeCenterFunction.scriptMessage( response, "alertBox({ txt : '파일 업로드에 실패하였습니다.', callBack : function(){ history.back(); } });" );
|
|
|
+ return "/common/blank";
|
|
|
+ }
|
|
|
+
|
|
|
+ dto.setFileOriginalName(fileName);
|
|
|
+ dto.setFileName(saveFileName);
|
|
|
+ dto.setFileExtension(ext);
|
|
|
+ dto.setFileSize(fileSize);
|
|
|
+ }
|
|
|
+
|
|
|
+ String sesId = LifeCenterSessionController.getSession(request, "sesId");
|
|
|
+
|
|
|
+ String title = dto.getTitle().trim();
|
|
|
+ String content = dto.getContent().trim();
|
|
|
+
|
|
|
+ dto.setTitle(title);
|
|
|
+ dto.setContent(content);
|
|
|
+ dto.setCreateBy(sesId);
|
|
|
|
|
|
- return "redirect:/board/content?postSeq=" + 1;
|
|
|
+ boardService.noticeInsert(dto);
|
|
|
+ int postSeq = dto.getPostSeq();
|
|
|
+
|
|
|
+ if (postSeq == 0) {
|
|
|
+ LifeCenterFunction.scriptMessage( response, "alertBox({ txt : '게시물 등록에 실패하였습니다.', callBack : function(){ history.back(); } });" );
|
|
|
+ return "/common/blank";
|
|
|
+ } else {
|
|
|
+ if (file.isEmpty() == false) {
|
|
|
+ boardService.fileUploadDataInsert(dto);
|
|
|
+ int fileIdx = dto.getFileIdx();
|
|
|
+ if (fileIdx == 0) {
|
|
|
+ LifeCenterFunction.scriptMessage( response, "alertBox({ txt : '게시물 등록에 실패하였습니다.', callBack : function(){ history.back(); } });" );
|
|
|
+ return "/common/blank";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return "redirect:/board/content?postSeq=" + dto.getPostSeq();
|
|
|
}
|
|
|
|
|
|
@RequestMapping("/content")
|
|
|
- public ModelAndView boardContent() {
|
|
|
+ public ModelAndView boardContent(
|
|
|
+ @RequestParam(value="postSeq", required=false, defaultValue="") int postSeq,
|
|
|
+ HttpServletRequest request, HttpServletResponse response) {
|
|
|
+ String sesId = LifeCenterSessionController.getSession( request, "sesId" );
|
|
|
+ String sesGroupIdx = LifeCenterSessionController.getSession( request, "sesGroupIdx" );
|
|
|
ModelAndView mv = setMV("board/content");
|
|
|
return mv;
|
|
|
}
|