Guest User

Untitled

a guest
Dec 16th, 2019
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 48.38 KB | None | 0 0
  1. ★ 1. BoardController.java
  2. package com.finger.spring.board.controller;
  3.  
  4. import java.util.HashMap;
  5. import java.util.List;
  6. import java.util.Map;
  7.  
  8. import org.slf4j.Logger;
  9. import org.slf4j.LoggerFactory;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.stereotype.Controller;
  12. import org.springframework.web.bind.annotation.RequestMapping;
  13. import org.springframework.web.bind.annotation.RequestMethod;
  14. import org.springframework.web.bind.annotation.ResponseBody;
  15. import org.springframework.web.multipart.MultipartFile;
  16.  
  17. import com.finger.spring.board.dto.BoardDto;
  18. import com.finger.spring.board.service.BoardService;
  19.  
  20. @Controller
  21. public class BoardController {
  22.  
  23. private static final Logger logger = LoggerFactory.getLogger(BoardController.class);
  24.  
  25. @Autowired
  26. BoardService boardService;
  27.  
  28. @RequestMapping(value = "/board/insert", method = RequestMethod.POST)
  29. @ResponseBody
  30. public int boardInsert(BoardDto dto) {
  31.  
  32. logger.debug("/board/insert");
  33.  
  34. return boardService.boardInsert(dto);
  35. }
  36.  
  37.  
  38.  
  39. @RequestMapping(value = "/board/insertFile", method = RequestMethod.POST)
  40. @ResponseBody
  41. public int boardInsertFile(BoardDto dto, MultipartFile file) throws Exception{
  42.  
  43. logger.debug("/board/insertFile");
  44. logger.debug("dto getUserSeq : " + dto.getUserSeq());
  45.  
  46. return boardService.boardInsertFile(dto, file);
  47. }
  48.  
  49. @RequestMapping(value = "/board/list", method = RequestMethod.GET)
  50. @ResponseBody
  51. public List<BoardDto> boardList(int limit, int offset, String searchWord) {
  52.  
  53. logger.debug("/board/list");
  54.  
  55. return boardService.boardList(limit, offset, searchWord);
  56. }
  57.  
  58. @RequestMapping(value = "/board/list/totalCnt", method = RequestMethod.GET)
  59. @ResponseBody
  60. public int boardListCnt(String searchWord) {
  61.  
  62. logger.debug("/board/listTotalCnt");
  63.  
  64. return boardService.boardListTotalCnt(searchWord);
  65. }
  66.  
  67. // @RequestMapping(value = "/board/detail", method = RequestMethod.GET)
  68. // @ResponseBody
  69. // public BoardDto boardDetail(int boardId) {
  70. //
  71. // logger.debug("/board/detail");
  72. //
  73. // return boardService.boardDetail(boardId);
  74. // }
  75.  
  76. @RequestMapping(value = "/board/detail", method = RequestMethod.GET)
  77. @ResponseBody
  78. public BoardDto boardDetail(int boardId, int userSeq) {
  79.  
  80. logger.debug("/board/detail");
  81.  
  82. return boardService.boardDetail(boardId, userSeq);
  83. }
  84.  
  85. @RequestMapping(value = "/board/update", method = RequestMethod.POST)
  86. @ResponseBody
  87. public int boardUpdate(BoardDto dto) {
  88.  
  89. logger.debug("/board/update");
  90.  
  91. return boardService.boardUpdate(dto);
  92. }
  93.  
  94. @RequestMapping(value = "/board/updateFile", method = RequestMethod.POST)
  95. @ResponseBody
  96. public int boardUpdateFile(BoardDto dto, MultipartFile file) throws Exception{
  97.  
  98. logger.debug("/board/updateFile");
  99.  
  100. return boardService.boardUpdateFile(dto, file);
  101. }
  102.  
  103. @RequestMapping(value = "/board/delete", method = RequestMethod.POST)
  104. @ResponseBody
  105. public int boardDelete(BoardDto dto) {
  106.  
  107. logger.debug("/board/delete");
  108.  
  109. return boardService.boardDelete(dto);
  110. }
  111.  
  112. //@RequestMapping(value = "/board/test", produces="text/plain;charset=UTF-8", method = RequestMethod.GET)
  113. @RequestMapping(value = "/board/test", method = RequestMethod.GET)
  114. @ResponseBody
  115. public Map<String, Object> boardTest() {
  116.  
  117. logger.debug("/board/test");
  118. String str = "�븞�뀞";
  119. Map<String, Object> map = new HashMap<String, Object>();
  120. map.put("msg", str);
  121. //return "{\"msg\":\"" + str + "\"}";
  122. return map;
  123. }
  124. }
  125.  
  126. ★2. BoardDao.java
  127.  
  128. package com.finger.spring.board.dao;
  129.  
  130. import java.util.List;
  131.  
  132. import org.apache.ibatis.annotations.Param;
  133.  
  134. import com.finger.spring.board.dto.BoardDto;
  135. import com.finger.spring.board.dto.BoardFileDto;
  136.  
  137. public interface BoardDao {
  138. public int boardInsert(BoardDto dto);
  139. public int boardInsertFile(BoardFileDto dto);
  140.  
  141. public List<BoardDto> boardList(@Param("limit") int limit, @Param("offset") int offset);
  142. public int boardListTotalCnt();
  143.  
  144. public List<BoardDto> boardListSearchWord(@Param("limit") int limit, @Param("offset") int offset, @Param("searchWord") String searchWord);
  145. public int boardListSearchWordTotalCnt(@Param("searchWord") String searchWord);
  146.  
  147. public BoardDto boardDetail(@Param("boardId") int boardId);
  148. public List<BoardFileDto> boardDetailFileList(@Param("boardId") int boardId);
  149. public int boardUpdate(BoardDto dto);
  150.  
  151. public List<String> boardDeleteFileUrl(@Param("boardId") int boardId);
  152. public int boardDelete(BoardDto dto);
  153. public int boardDeleteFile(@Param("boardId") int boardId);
  154.  
  155. public int boardUserReadCnt(@Param("boardId") int boardId, @Param("userSeq") int userSeq);
  156. public int boardInsertUserRead(@Param("boardId") int boardId, @Param("userSeq") int userSeq);
  157. public int boardUpdateReadCnt(@Param("boardId") int boardId);
  158. }
  159.  
  160.  
  161. ★ 3. boardMapper.xml
  162.  
  163. <?xml version="1.0" encoding="UTF-8"?>
  164. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  165. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  166. <mapper namespace="com.finger.spring.board.dao.BoardDao">
  167.  
  168. <insert id="boardInsert" parameterType="com.finger.spring.board.dto.BoardDto" useGeneratedKeys="true" keyProperty="boardId">
  169. insert into board ( USER_SEQ, TITLE, CONTENT, REG_DT, READ_COUNT )
  170. values ( #{userSeq}, #{title}, #{content}, now(), 0 );
  171. </insert>
  172.  
  173. <insert id="boardInsertFile" parameterType="com.finger.spring.board.dto.BoardDto">
  174. insert into board_file ( BOARD_ID, FILE_NAME, FILE_SIZE, FILE_CONTENT_TYPE, FILE_URL )
  175. values ( #{boardId}, #{fileName}, #{fileSize}, #{fileContentType}, #{fileUrl} );
  176. </insert>
  177.  
  178. <resultMap id="boardMap" type="com.finger.spring.board.dto.BoardDto">
  179. <result property="boardId" column="board_id" />
  180. <result property="userSeq" column="user_seq" />
  181. <result property="userName" column="user_name" />
  182. <result property="userProfileImageUrl" column="user_profile_image_url" />
  183. <result property="title" column="title" />
  184. <result property="content" column="content" />
  185. <result property="regDt" column="reg_dt" />
  186. <result property="readCount" column="read_count" />
  187. </resultMap>
  188.  
  189. <select id="boardList" resultMap="boardMap">
  190. SELECT b.BOARD_ID,
  191. b.USER_SEQ,
  192. u.USER_NAME,
  193. u.USER_PROFILE_IMAGE_URL,
  194. b.TITLE,
  195. b.CONTENT,
  196. b.REG_DT,
  197. b.READ_COUNT
  198. FROM board b, user u
  199. WHERE b.USER_SEQ = u.USER_SEQ
  200. ORDER BY BOARD_ID DESC
  201. LIMIT #{limit} OFFSET #{offset}
  202. </select>
  203.  
  204. <select id="boardListSearchWord" resultMap="boardMap">
  205. SELECT b.BOARD_ID,
  206. b.USER_SEQ,
  207. u.USER_NAME,
  208. u.USER_PROFILE_IMAGE_URL,
  209. b.TITLE,
  210. b.CONTENT,
  211. b.REG_DT,
  212. b.READ_COUNT
  213. FROM board b, user u
  214. WHERE b.USER_SEQ = u.USER_SEQ
  215. AND TITLE LIKE CONCAT('%', #{searchWord}, '%')
  216. ORDER BY BOARD_ID DESC
  217. LIMIT #{limit} OFFSET #{offset}
  218. </select>
  219.  
  220.  
  221. <select id="boardListTotalCnt" resultType="int">
  222. SELECT count(*) FROM board
  223. </select>
  224.  
  225. <select id="boardListSearchWordTotalCnt" parameterType="String" resultType="int">
  226. SELECT count(*) FROM board WHERE TITLE LIKE CONCAT('%', #{searchWord}, '%')
  227. </select>
  228.  
  229. <select id="boardDetail" parameterType="int" resultType="com.finger.spring.board.dto.BoardDto">
  230. SELECT b.BOARD_ID as boardId,
  231. b.USER_SEQ as userSeq,
  232. u.USER_NAME as userName,
  233. u.USER_PROFILE_IMAGE_URL as userProfileImageUrl,
  234. b.TITLE as title,
  235. b.CONTENT as content,
  236. b.REG_DT as regDt,
  237. b.READ_COUNT as readCount
  238. FROM board b, user u
  239. WHERE b.USER_SEQ = u.USER_SEQ
  240. AND b.BOARD_ID = #{boardId}
  241. </select>
  242.  
  243. <update id="boardUpdate" parameterType="com.finger.spring.board.dto.BoardDto">
  244. UPDATE board
  245. set TITLE = #{title}, CONTENT = #{content}
  246. WHERE BOARD_ID = #{boardId}
  247. </update>
  248.  
  249. <delete id="boardDeleteFile" parameterType="int">
  250. DELETE from board_file
  251. WHERE BOARD_ID = #{boardId}
  252. </delete>
  253.  
  254. <delete id="boardDelete" parameterType="int">
  255. DELETE from board
  256. WHERE BOARD_ID = #{boardId}
  257. </delete>
  258.  
  259. <select id="boardUserReadCnt" resultType="int">
  260. SELECT count(*) FROM board_user_read WHERE board_id = #{boardId} and user_seq = #{userSeq}
  261. </select>
  262.  
  263. <insert id="boardInsertUserRead">
  264. INSERT INTO board_user_read ( board_id, user_seq ) VALUES ( #{boardId}, #{userSeq} )
  265. </insert>
  266.  
  267. <update id="boardUpdateReadCnt">
  268. UPDATE board set READ_COUNT = READ_COUNT + 1 WHERE BOARD_ID = #{boardId}
  269. </update>
  270.  
  271. <resultMap id="boardFileMap" type="com.finger.spring.board.dto.BoardFileDto">
  272. <result property="boardId" column="board_id" />
  273. <result property="fileId" column="file_id" />
  274. <result property="fileName" column="file_name" />
  275. <result property="fileSize" column="file_size" />
  276. <result property="fileContentType" column="file_content_type" />
  277. <result property="fileUrl" column="file_url" />
  278. <result property="regDt" column="reg_dt" />
  279. </resultMap>
  280.  
  281. <select id="boardDetailFileList" resultMap="boardFileMap">
  282. SELECT BOARD_ID, FILE_ID, FILE_NAME, FILE_SIZE, FILE_CONTENT_TYPE, FILE_URL, REG_DT
  283. FROM board_file
  284. WHERE BOARD_ID = #{boardId}
  285. </select>
  286.  
  287. <select id="boardDeleteFileUrl" parameterType="int" resultType="String">
  288. SELECT file_url
  289. FROM board_file
  290. WHERE BOARD_ID = #{boardId}
  291. </select>
  292.  
  293. </mapper>
  294.  
  295.  
  296. ★ 4. BoardDto.java
  297.  
  298. package com.finger.spring.board.dto;
  299.  
  300.  
  301. import java.util.Date;
  302. import java.util.List;
  303.  
  304. import com.fasterxml.jackson.annotation.JsonFormat;
  305.  
  306. public class BoardDto {
  307. private int boardId;
  308. private String userSeq;
  309. private String userName;
  310. private String userProfileImageUrl;
  311.  
  312. private String title;
  313. private String content;
  314. @JsonFormat(pattern = "yyyy-MM-dd HH:mm", timezone="Asia/Seoul")
  315. private Date regDt;
  316. private int readCount;
  317.  
  318. private List<BoardFileDto> fileList;
  319.  
  320.  
  321. public int getBoardId() {
  322. return boardId;
  323. }
  324. public void setBoardId(int boardId) {
  325. this.boardId = boardId;
  326. }
  327. public String getUserSeq() {
  328. return userSeq;
  329. }
  330. public void setUserSeq(String userSeq) {
  331. this.userSeq = userSeq;
  332. }
  333. public String getUserName() {
  334. return userName;
  335. }
  336. public void setUserName(String userName) {
  337. this.userName = userName;
  338. }
  339.  
  340. public String getUserProfileImageUrl() {
  341. return userProfileImageUrl;
  342. }
  343. public void setUserProfileImageUrl(String userProfileImageUrl) {
  344. if( userProfileImageUrl == null ) {
  345. this.userProfileImageUrl = "/resources/images/noProfile.png";
  346. }else {
  347. this.userProfileImageUrl = userProfileImageUrl;
  348. }
  349. }
  350.  
  351. public String getTitle() {
  352. return title;
  353. }
  354. public void setTitle(String title) {
  355. this.title = title;
  356. }
  357. public String getContent() {
  358. return content;
  359. }
  360. public void setContent(String content) {
  361. this.content = content;
  362. }
  363. public Date getRegDt() {
  364. return regDt;
  365. }
  366. public void setRegDt(Date regDt) {
  367. this.regDt = regDt;
  368. }
  369. public int getReadCount() {
  370. return readCount;
  371. }
  372. public void setReadCount(int readCount) {
  373. this.readCount = readCount;
  374. }
  375.  
  376. public List<BoardFileDto> getFileList() {
  377. return fileList;
  378. }
  379. public void setFileList(List<BoardFileDto> fileList) {
  380. this.fileList = fileList;
  381. }
  382.  
  383. }
  384.  
  385.  
  386.  
  387. ★ 5. BoardFileDto.java
  388.  
  389. package com.finger.spring.board.dto;
  390.  
  391.  
  392. import java.util.Date;
  393.  
  394. public class BoardFileDto {
  395. private int fileId;
  396. private int boardId;
  397. private String fileName;
  398. private long fileSize;
  399. private String fileContentType;
  400. private String fileUrl;
  401. private Date regDt;
  402.  
  403. public int getFileId() {
  404. return fileId;
  405. }
  406. public void setFileId(int fileId) {
  407. this.fileId = fileId;
  408. }
  409. public int getBoardId() {
  410. return boardId;
  411. }
  412. public void setBoardId(int boardId) {
  413. this.boardId = boardId;
  414. }
  415. public String getFileName() {
  416. return fileName;
  417. }
  418. public void setFileName(String fileName) {
  419. this.fileName = fileName;
  420. }
  421. public long getFileSize() {
  422. return fileSize;
  423. }
  424. public void setFileSize(long fileSize) {
  425. this.fileSize = fileSize;
  426. }
  427. public String getFileContentType() {
  428. return fileContentType;
  429. }
  430. public void setFileContentType(String fileContentType) {
  431. this.fileContentType = fileContentType;
  432. }
  433.  
  434. public String getFileUrl() {
  435. return fileUrl;
  436. }
  437. public void setFileUrl(String fileUrl) {
  438. this.fileUrl = fileUrl;
  439. }
  440. public Date getRegDt() {
  441. return regDt;
  442. }
  443. public void setRegDt(Date regDt) {
  444. this.regDt = regDt;
  445. }
  446. @Override
  447. public String toString() {
  448. return "boardFile [fileId=" + fileId + ", boardId=" + boardId + ", fileName=" + fileName
  449. + ", fileSize=" + fileSize + ", fileContentType=" + fileContentType + "]";
  450. }
  451. }
  452.  
  453. ★ 6. BoardService.java
  454.  
  455. package com.finger.spring.board.service;
  456.  
  457. import java.util.List;
  458.  
  459. import org.springframework.web.multipart.MultipartFile;
  460.  
  461. import com.finger.spring.board.dto.BoardDto;
  462.  
  463.  
  464. public interface BoardService {
  465. public int boardInsert(BoardDto dto);
  466.  
  467. public int boardInsertFile(BoardDto dto, MultipartFile file) throws Exception;
  468.  
  469. public List<BoardDto> boardList(int limit, int offset, String searchWord);
  470.  
  471. public int boardListTotalCnt(String searchWord);
  472.  
  473. //public BoardDto boardDetail(int boardId);
  474. public BoardDto boardDetail(int boardId, int userSeq);
  475.  
  476. public int boardUpdate(BoardDto dto);
  477.  
  478. public int boardUpdateFile(BoardDto dto, MultipartFile file) throws Exception;
  479.  
  480. public int boardDelete(BoardDto dto);
  481.  
  482.  
  483. public int boardUpdateReadCnt(int boardId);
  484. }
  485.  
  486. ★ 7. BoardServiceImpl.java
  487.  
  488. package com.finger.spring.board.service;
  489.  
  490. import java.io.File;
  491. import java.util.Iterator;
  492. import java.util.List;
  493. import java.util.UUID;
  494.  
  495. import org.apache.commons.io.FilenameUtils;
  496. import org.slf4j.Logger;
  497. import org.slf4j.LoggerFactory;
  498. import org.springframework.beans.factory.annotation.Autowired;
  499. import org.springframework.stereotype.Service;
  500. import org.springframework.transaction.annotation.Transactional;
  501. import org.springframework.web.multipart.MultipartFile;
  502.  
  503. import com.finger.spring.board.controller.BoardController;
  504. import com.finger.spring.board.dao.BoardDao;
  505.  
  506. import com.finger.spring.board.dto.BoardDto;
  507. import com.finger.spring.board.dto.BoardFileDto;
  508.  
  509. @Service
  510. public class BoardServiceImpl implements BoardService{
  511.  
  512. private static final Logger logger = LoggerFactory.getLogger(BoardController.class);
  513.  
  514. @Autowired
  515. BoardDao boardDao;
  516.  
  517. @Override
  518. public int boardInsert(BoardDto dto) {
  519. return boardDao.boardInsert(dto);
  520. }
  521. // C:\Users\User\eclipse-workspace\finger\src\main\webapp\resources\boardFiles
  522. String boardUploadRealPath =
  523. "C:" + File.separator + "Users" + File.separator + "User" + File.separator +
  524. "eclipse-workspace" + File.separator + "finger" + File.separator + "src" + File.separator + "main" + File.separator + "webapp" + File.separator +
  525. "resources" + File.separator + "boardFiles";
  526.  
  527. String boardDeleteRealPath =
  528. "C:" + File.separator + "Users" + File.separator + "User" + File.separator +
  529. "eclipse-workspace" + File.separator + "finger" + File.separator + "src" + File.separator + "main" + File.separator + "webapp" + File.separator +
  530. "resources" + File.separator + "boardFiles" ;
  531.  
  532. String boardFileFolder = "resources/boardFiles";
  533.  
  534. @Override
  535. @Transactional("txManager")
  536. public int boardInsertFile(BoardDto dto, MultipartFile file) throws Exception{
  537. //with jdbcTemplate
  538. //int boardId = boardDao.boardInsert(dto);
  539.  
  540. boardDao.boardInsert(dto);
  541. int boardId = dto.getBoardId();
  542.  
  543. logger.debug("boardId : " + boardId);
  544.  
  545. if( file != null ) {
  546. //Random Fild Id
  547. UUID uuid = UUID.randomUUID();
  548.  
  549. //file extention
  550. String extension = FilenameUtils.getExtension(file.getOriginalFilename()); // vs FilenameUtils.getBaseName()
  551.  
  552. String savingFileName = uuid + "." + extension;
  553.  
  554. File saveFile = new File(boardUploadRealPath, savingFileName);
  555. file.transferTo(saveFile);
  556.  
  557. //File Save to folder
  558. BoardFileDto fileDto = new BoardFileDto();
  559. fileDto.setFileContentType(file.getContentType());
  560.  
  561.  
  562. logger.debug("fileDto.getFileContentType : " + fileDto.getFileContentType());
  563.  
  564. fileDto.setFileName(file.getOriginalFilename());
  565. fileDto.setFileSize(file.getSize());
  566.  
  567. String boardFileUrl = boardFileFolder + "/" + savingFileName;
  568. fileDto.setFileUrl(boardFileUrl);
  569.  
  570. fileDto.setBoardId(boardId);
  571.  
  572. boardDao.boardInsertFile(fileDto);
  573. }
  574.  
  575. return boardId;
  576. }
  577.  
  578.  
  579.  
  580. @Override
  581. public List<BoardDto> boardList(int limit, int offset, String searchWord) {
  582.  
  583. logger.debug("searchWord : " + searchWord);
  584.  
  585. if("".equals(searchWord)) {
  586. return boardDao.boardList(limit, offset);
  587. }else {
  588. return boardDao.boardListSearchWord(limit, offset, searchWord);
  589. }
  590. }
  591.  
  592. @Override
  593. public int boardListTotalCnt(String searchWord) {
  594.  
  595. if("".equals(searchWord)) {
  596. return boardDao.boardListTotalCnt();
  597. }else {
  598. return boardDao.boardListSearchWordTotalCnt(searchWord);
  599. }
  600. }
  601.  
  602.  
  603. // @Override
  604. // public BoardDto boardDetail(int boardId) {
  605. //
  606. // BoardDto dto = boardDao.boardDetail(boardId);
  607. // List<BoardFileDto> fileList = boardDao.boardDetailFileList(dto.getBoardId());
  608. // dto.setFileList(fileList);
  609. // return dto;
  610. // }
  611.  
  612. @Override
  613. public BoardDto boardDetail(int boardId, int userSeq) {
  614. //議고쉶�닔 泥섎━
  615. int viewCnt = boardDao.boardUserReadCnt(boardId, userSeq);
  616.  
  617. if( viewCnt == 0 ) {
  618. boardDao.boardInsertUserRead(boardId, userSeq);
  619. boardDao.boardUpdateReadCnt(boardId);
  620. }
  621.  
  622. BoardDto dto = boardDao.boardDetail(boardId);
  623. List<BoardFileDto> fileList = boardDao.boardDetailFileList(dto.getBoardId());
  624. dto.setFileList(fileList);
  625. return dto;
  626. }
  627.  
  628. @Override
  629. public int boardUpdate(BoardDto dto) {
  630. return boardDao.boardUpdate(dto);
  631. }
  632.  
  633. @Override
  634. @Transactional("txManager")
  635. public int boardUpdateFile(BoardDto dto, MultipartFile file) throws Exception{
  636.  
  637. int ret = boardDao.boardUpdate(dto);
  638.  
  639. if( file != null ) {
  640. //delete first
  641. boardDao.boardDeleteFile(dto.getBoardId());
  642.  
  643. //Random Fild Id
  644. UUID uuid = UUID.randomUUID();
  645.  
  646. //file extention
  647. String extension = FilenameUtils.getExtension(file.getOriginalFilename()); // vs FilenameUtils.getBaseName()
  648.  
  649. String savingFileName = uuid + "." + extension;
  650.  
  651. File saveFile = new File(boardUploadRealPath, savingFileName);
  652. file.transferTo(saveFile);
  653.  
  654. //File Save to folder
  655. BoardFileDto fileDto = new BoardFileDto();
  656. fileDto.setFileContentType(file.getContentType());
  657.  
  658.  
  659. logger.debug("fileDto.getFileContentType : " + fileDto.getFileContentType());
  660.  
  661. fileDto.setFileName(file.getOriginalFilename());
  662. fileDto.setFileSize(file.getSize());
  663.  
  664. String boardFileUrl = boardFileFolder + "/" + savingFileName;
  665. fileDto.setFileUrl(boardFileUrl);
  666.  
  667. fileDto.setBoardId(dto.getBoardId());
  668.  
  669. boardDao.boardInsertFile(fileDto);
  670. }
  671.  
  672. return ret;
  673. }
  674.  
  675. @Override
  676. @Transactional("txManager")
  677. public int boardDelete(BoardDto dto) {
  678.  
  679. List<String> fileUrlList = boardDao.boardDeleteFileUrl(dto.getBoardId());
  680. for(String fileUrl : fileUrlList) {
  681. File file = new File(boardDeleteRealPath, fileUrl);
  682. logger.debug("file : " + file.getName());
  683.  
  684. if(file.exists()) {
  685. file.delete();
  686. }
  687. }
  688.  
  689. boardDao.boardDeleteFile(dto.getBoardId());
  690. int ret = boardDao.boardDelete(dto);
  691.  
  692. return ret;
  693. }
  694.  
  695.  
  696. @Override
  697. public int boardUpdateReadCnt(int boardId) {
  698. return boardDao.boardUpdateReadCnt(boardId);
  699. }
  700. }
  701.  
  702.  
  703. ★ 8. board.jsp
  704.  
  705.  
  706.  
  707. <%@ page language="java" contentType="text/html; charset=EUC-KR"
  708. pageEncoding="EUC-KR"%>
  709. <%@ page import = "com.finger.spring.user.dto.*" %>
  710. <%
  711. UserDto userDto = (UserDto) session.getAttribute("userDto");
  712. String userName = "";
  713.  
  714. if(userDto != null){
  715. System.out.println(userDto.getUserSeq());
  716. userName = userDto.getUserName();
  717. }
  718. %>
  719. <!DOCTYPE html>
  720. <html lang="en">
  721. <head>
  722. <title>Bootstrap Example</title>
  723. <meta charset="utf-8">
  724. <meta name="viewport" content="width=device-width, initial-scale=1">
  725. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
  726. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  727. <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
  728. <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
  729.  
  730. <script src="//cdn.jsdelivr.net/npm/[email protected]/build/alertify.min.js"></script>
  731. <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/[email protected]/build/css/alertify.min.css"/>
  732. <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/[email protected]/build/css/themes/default.min.css"/>
  733.  
  734. <link rel="stylesheet" href="/resources/css/common.css">
  735. </head>
  736. <body>
  737.  
  738. <nav class="navbar navbar-expand-sm bg-light">
  739. <ul class="navbar-nav">
  740. <li class="nav-item">
  741. <a class="nav-link" href="/board">게시판</a>
  742. </li>
  743. <li class="nav-item">
  744. <a class="nav-link" href="/logout">logout</a>
  745. </li>
  746. </ul>
  747. </nav>
  748. <br>
  749.  
  750. <div class="container">
  751.  
  752. <h2>게시판</h2>
  753.  
  754. <div class="input-group mb-3">
  755. <input id="inputSearchWord" type="text" class="form-control" placeholder="Search">
  756. <div class="input-group-append">
  757. <button id="btnSearchWord" class="btn btn-success">Go</button>
  758. </div>
  759. </div>
  760.  
  761. <table class="table table-hover">
  762. <thead>
  763. <tr>
  764. <th>#</th>
  765. <th>제목</th>
  766. <th>작성자</th>
  767. <th>작성일시</th>
  768. <th>조회수</th>
  769. </tr>
  770. </thead>
  771. <tbody id="boardTbody">
  772.  
  773. </tbody>
  774. </table>
  775.  
  776. <div id="paginationWrapper"></div>
  777.  
  778. <button class="btn btn-sm btn-primary" id="btnBoardInsertForm">글쓰기</button>
  779. </div>
  780.  
  781.  
  782. <!-- Modal insert-->
  783. <div class="modal fade" id="boardInsertModal">
  784. <div class="modal-dialog modal-simple">
  785. <form class="modal-content">
  786. <!-- Modal Header -->
  787. <div class="modal-header">
  788. <h4 class="modal-title">글쓰기</h4>
  789. <button type="button" class="close" data-dismiss="modal">&times;</button>
  790. </div>
  791. <div class="modal-body">
  792. <div class="row">
  793. <div class="col-xl-12 form-group">
  794. <input id="titleInsert" type="text" class="form-control" name="title" placeholder="제목">
  795. </div>
  796. <div class="col-xl-12 form-group">
  797. <textarea id="contentInsert" class="form-control" rows="5" placeholder="내용"></textarea>
  798. </div>
  799. <div class="col-xl-12 form-group">
  800. <div class="checkbox-custom checkbox-primary">
  801. <input type="checkbox" id="chkFileUploadInsert" />
  802. <label for="chkFileUploadInsert">파일 추가</label>
  803. </div>
  804. </div>
  805. <div class="col-xl-12 form-group" style="display:none;" id="imgFileUploadInsertWrapper">
  806. <input type="file" id="inputFileUploadInsert">
  807. <div class="thumbnail-wrapper">
  808. <img id="imgFileUploadInsert">
  809. </div>
  810. </div>
  811. <div class="col-md-12 float-right">
  812. <button id="btnBoardInsert" class="btn btn-sm btn-primary btn-outline" data-dismiss="modal" type="button">등록</button>
  813. </div>
  814. </div>
  815. </div>
  816. </form>
  817. </div>
  818. </div>
  819. <!-- End Modal -->
  820.  
  821. <!-- Modal detail-->
  822. <div class="modal fade" id="boardDetailModal">
  823. <div class="modal-dialog modal-simple">
  824. <div class="modal-content">
  825. <!-- Modal Header -->
  826. <div class="modal-header">
  827. <h4 class="modal-title">글 상세</h4>
  828. <button type="button" class="close" data-dismiss="modal">&times;</button>
  829. </div>
  830.  
  831. <div class="modal-body">
  832.  
  833. <div class="example table-responsive">
  834. <table class="table table-hover">
  835. <tbody>
  836. <tr><td>글번호</td><td id="boardIdDetail">#</td></tr>
  837. <tr><td>제목</td><td id="titleDetail">#</td></tr>
  838. <tr><td>내용</td><td id="contentDetail">#</td></tr>
  839. <tr><td>작성자</td><td id="userNameDetail">#</td></tr>
  840. <tr><td>작성일시</td><td id="regDtDetail">#</td></tr>
  841. <tr><td>조회수</td><td id="readCountDetail">#</td></tr>
  842. <tr><td>첨부파일</td><td id="fileListDetail">#</td></tr>
  843. </tbody>
  844. </table>
  845. </div>
  846. <button id="btnBoardUpdateForm" class="btn btn-sm btn-primary btn-outline" data-dismiss="modal" type="button">글 수정하기</button>
  847. <button id="btnBoardDeleteConfirm" class="btn btn-sm btn-warning btn-outline" data-dismiss="modal" type="button">글 삭제하기</button>
  848.  
  849. </div>
  850. </div>
  851. </div>
  852. </div>
  853. <!-- End Modal -->
  854.  
  855. <!-- Modal update-->
  856. <div class="modal fade" id="boardUpdateModal">
  857. <div class="modal-dialog modal-simple">
  858. <form class="modal-content">
  859. <!-- Modal Header -->
  860. <div class="modal-header">
  861. <h4 class="modal-title">글수정</h4>
  862. <button type="button" class="close" data-dismiss="modal">&times;</button>
  863. </div>
  864. <div class="modal-body">
  865. <div class="row">
  866. <div class="col-xl-12 form-group">
  867. <input id="titleUpdate" type="text" class="form-control" name="title" placeholder="제목">
  868. </div>
  869. <div class="col-xl-12 form-group">
  870. <textarea id="contentUpdate" class="form-control" rows="5" placeholder="내용"></textarea>
  871. </div>
  872. <div class="col-xl-12 form-group">
  873. 첨부파일 : <span id="fileListUpdate"></span>
  874. </div>
  875. <div class="col-xl-12 form-group">
  876. <div class="checkbox-custom checkbox-primary">
  877. <input type="checkbox" id="chkFileUploadUpdate" />
  878. <label for="chkFileUploadUpdate">파일 변경</label>
  879. </div>
  880. </div>
  881. <div class="col-xl-12 form-group" style="display:none;" id="imgFileUploadUpdateWrapper">
  882. <input type="file" id="inputFileUploadUpdate">
  883. <div class="thumbnail-wrapper">
  884. <img id="imgFileUploadUpdate">
  885. </div>
  886. </div>
  887. <div class="col-md-12 float-right">
  888. <button id="btnBoardUpdate" class="btn btn-sm btn-primary btn-outline" data-dismiss="modal" type="button">수정</button>
  889. </div>
  890. </div>
  891. </div>
  892. </form>
  893. </div>
  894. </div>
  895. <!-- End Modal -->
  896.  
  897.  
  898. <script src="/resources/js/util.js"></script>
  899. <script>
  900. var LIST_ROW_COUNT = 10; //limit
  901. var OFFSET = 0;
  902. var PAGE_COUNT_PER_BLOCK = 10; // pagination link 갯수
  903. var TOTAL_LIST_ITEM_COUNT = 0;
  904. var CURRENT_PAGE_INDEX = 1;
  905.  
  906. var SEARCH_WORD = "";
  907.  
  908. $(document).ready(function() {
  909.  
  910. boardList();
  911.  
  912. $("#btnBoardInsertForm").click(function(){
  913. $("#titleInsert").val("");
  914. $("#contentInsert").val("");
  915. $("#chkFileUploadInsert").prop("checked", false);
  916. $("#inputFileUploadInsert").val("");
  917. $("#imgFileUploadInsert").removeAttr("src");
  918. //$("#imgFileUploadInsert").attr("src", "");
  919. $("#imgFileUploadInsertWrapper").hide();
  920.  
  921. $("#boardInsertModal").modal("show");
  922. });
  923.  
  924. $("#btnBoardInsert").click(function(){
  925.  
  926. if( validateInsert() ){
  927. boardInsert();
  928. }
  929. });
  930.  
  931. $("#btnBoardUpdateForm").click(function(){
  932.  
  933. var boardId = $("#boardDetailModal").attr("data-boardId");
  934. $("#boardUpdateModal").attr("data-boardId", boardId);
  935.  
  936. $("#titleUpdate").val( $("#titleDetail").html() );
  937. $("#contentUpdate").val( $("#contentDetail").html() );
  938.  
  939. // $("#fileListDetail").append(
  940. // '<span class="fileName">' + fileName + '</span>');
  941. var fileName = $("#fileListDetail").find(".fileName").html();
  942. $("#fileListUpdate").html( '<span class="fileName">' + fileName + '</span>');
  943.  
  944. $("#chkFileUploadUpdate").prop("checked", false);
  945. $("#inputFileUploadUpdate").val("");
  946. $("#imgFileUploadUpdate").attr("src", "");
  947. //$("#imgFileUploadUpdate").removeAttr("src");
  948. $("#imgFileUploadUpdateWrapper").hide();
  949.  
  950. $("#boardDetailModal").modal("hide");
  951. $("#boardUpdateModal").modal("show");
  952. });
  953.  
  954. $("#btnBoardUpdate").click(function(){
  955.  
  956. if( validateUpdate() ){
  957. boardUpdate();
  958. }
  959. });
  960.  
  961. $("#btnBoardDeleteConfirm").click(function(){
  962. alertify.confirm('Upwiden', '이 글을 삭제하시겠습니까?',
  963. function() {
  964. boardDelete();
  965. },
  966. function(){
  967. console.log('cancel');
  968. }
  969. );
  970. });
  971.  
  972. //file upload..
  973. //Insert
  974. $("#chkFileUploadInsert").change(function(){
  975. if( $(this).prop("checked")){
  976. $("#imgFileUploadInsertWrapper").show();
  977. }else{
  978. $("#inputFileUploadInsert").val("");
  979. $("#imgFileUploadInsert").attr("src", "");
  980. $("#imgFileUploadInsertWrapper").hide();
  981. }
  982. });
  983.  
  984. $("#inputFileUploadInsert").change(function(e){
  985.  
  986. if( this.files && this.files[0] ){
  987. var reader = new FileReader();
  988. reader.onload = function(e){
  989. $("#imgFileUploadInsert").attr("src", e.target.result);
  990. }
  991. reader.readAsDataURL(this.files[0]);
  992. }
  993. });
  994.  
  995. //Update
  996. $("#chkFileUploadUpdate").change(function(){
  997. if( $(this).prop("checked")){
  998. $("#imgFileUploadUpdateWrapper").show();
  999. }else{
  1000. $("#inputFileUploadUpdate").val("");
  1001. $("#imgFileUploadUpdate").attr("src", "");
  1002. $("#imgFileUploadUpdateWrapper").hide();
  1003. }
  1004. });
  1005.  
  1006. $("#inputFileUploadUpdate").change(function(e){
  1007.  
  1008. if( this.files && this.files[0] ){
  1009. var reader = new FileReader();
  1010. reader.onload = function(e){
  1011. $("#imgFileUploadUpdate").attr("src", e.target.result);
  1012. }
  1013. reader.readAsDataURL(this.files[0]);
  1014. }
  1015. });
  1016.  
  1017.  
  1018. //Search
  1019. $("#btnSearchWord").click(function(e){
  1020. var searchWord = $("#inputSearchWord").val();
  1021.  
  1022. if( searchWord != "" ){
  1023. SEARCH_WORD = searchWord;
  1024. }else{
  1025. SEARCH_WORD = "";
  1026. }
  1027.  
  1028. boardList();
  1029. });
  1030.  
  1031. });
  1032.  
  1033. function validateInsert(){
  1034. var isTitleInsertValid = false;
  1035. var isContentInsertValid = false;
  1036.  
  1037. var titleInsert = $("#titleInsert").val();
  1038. var titleInsertLength = titleInsert.length;
  1039.  
  1040. if( titleInsertLength > 0 ){
  1041. isTitleInsertValid = true;
  1042. }
  1043.  
  1044. var contentInsertValue = $("#contentInsert").val();
  1045. var contentInsertLength = contentInsertValue.length;
  1046.  
  1047. if( contentInsertLength > 0 ){
  1048. isContentInsertValid = true;
  1049. }
  1050.  
  1051. if( isTitleInsertValid && isContentInsertValid ){
  1052. return true;
  1053. }else{
  1054. return false;
  1055. }
  1056. }
  1057.  
  1058. function boardInsert(){
  1059.  
  1060. var formData = new FormData();
  1061. formData.append("userSeq", '<%=userDto.getUserSeq()%>');
  1062. formData.append("title", $("#titleInsert").val());
  1063. formData.append("content", $("#contentInsert").val());
  1064. formData.append("file", $("#inputFileUploadInsert")[0].files[0]);
  1065. console.log(formData.get('userSeq'));
  1066. console.log(formData.get('title'));
  1067. console.log(formData.get('content'));
  1068. $.ajax(
  1069. {
  1070. type : 'post',
  1071. url : '/board/insertFile',
  1072. dataType : 'json',
  1073. data : formData,
  1074. contentType: false, // forcing jQuery not to add a Content-Type header for you, otherwise, the boundary string will be missing from it
  1075. processData: false, // otherwise, jQuery will try to convert your FormData into a string, which will fail.
  1076. beforeSend : function(xhr){
  1077. //xhr.setRequestHeader("ApiKey", "asdfasxdfasdfasdf");
  1078. xhr.setRequestHeader("AJAX", true);
  1079. },
  1080. success : function(data, status, xhr) {
  1081.  
  1082. if( data ){
  1083. alertify.success('글이 등록되었습니다.');
  1084. boardList();
  1085. }
  1086. },
  1087. error: function(jqXHR, textStatus, errorThrown)
  1088. {
  1089. if( jqXHR.responseText == "timeout" ){
  1090. window.location.href = "/login"
  1091. }else{
  1092. alertify.notify(
  1093. 'Opps!! 글 등록 과정에 문제가 생겼습니다.',
  1094. 'error', //'error','warning','message'
  1095. 3, //-1
  1096. function(){
  1097. console.log(jqXHR.responseText);
  1098. }
  1099. );
  1100. }
  1101.  
  1102. }
  1103. });
  1104. }
  1105.  
  1106. function validateUpdate(){
  1107. var isTitleUpdateValid = false;
  1108. var isContentUpdateValid = false;
  1109.  
  1110. var titleUpdate = $("#titleUpdate").val();
  1111. var titleUpdateLength = titleUpdate.length;
  1112.  
  1113. if( titleUpdateLength > 0 ){
  1114. isTitleUpdateValid = true;
  1115. }
  1116.  
  1117. var contentUpdateValue = $("#contentUpdate").val();
  1118. var contentUpdateLength = contentUpdateValue.length;
  1119.  
  1120. if( contentUpdateLength > 0 ){
  1121. isContentUpdateValid = true;
  1122. }
  1123.  
  1124. if( isTitleUpdateValid && isContentUpdateValid ){
  1125. return true;
  1126. }else{
  1127. return false;
  1128. }
  1129. }
  1130.  
  1131. function boardUpdate(){
  1132.  
  1133. var formData = new FormData();
  1134. formData.append("boardId", $("#boardUpdateModal").attr("data-boardId"));
  1135. formData.append("userSeq", '<%=userDto.getUserSeq()%>');
  1136. formData.append("title", $("#titleUpdate").val());
  1137. formData.append("content", $("#contentUpdate").val());
  1138. formData.append("file", $("#inputFileUploadUpdate")[0].files[0]);
  1139.  
  1140. $.ajax(
  1141. {
  1142. type : 'post',
  1143. url : '/board/updateFile',
  1144. dataType : 'json',
  1145. data : formData,
  1146. contentType: false, // forcing jQuery not to add a Content-Type header for you, otherwise, the boundary string will be missing from it
  1147. processData: false, // otherwise, jQuery will try to convert your FormData into a string, which will fail.
  1148. beforeSend : function(xhr){
  1149. //xhr.setRequestHeader("ApiKey", "asdfasxdfasdfasdf");
  1150. xhr.setRequestHeader("AJAX", true);
  1151. },
  1152. success : function(data, status, xhr) {
  1153.  
  1154. if( data ){
  1155. alertify.success('글이 수정되었습니다.');
  1156. boardList();
  1157. }
  1158. },
  1159. error: function(jqXHR, textStatus, errorThrown)
  1160. {
  1161. if( jqXHR.responseText == "timeout" ){
  1162. window.location.href = "/login"
  1163. }else{
  1164. alertify.notify(
  1165. 'Opps!! 글 수정 과정에 문제가 생겼습니다.',
  1166. 'error', //'error','warning','message'
  1167. 3, //-1
  1168. function(){
  1169. console.log(jqXHR.responseText);
  1170. }
  1171. );
  1172. }
  1173. }
  1174. });
  1175. }
  1176.  
  1177. function boardDelete(){
  1178. $.ajax(
  1179. {
  1180. type : 'post',
  1181. url : '/board/delete',
  1182. dataType : 'json',
  1183. data :
  1184. {
  1185. boardId: $("#boardDetailModal").attr("data-boardId")
  1186. },
  1187. beforeSend : function(xhr){
  1188. //xhr.setRequestHeader("ApiKey", "asdfasxdfasdfasdf");
  1189. xhr.setRequestHeader("AJAX", true);
  1190. },
  1191. success : function(data, status, xhr) {
  1192.  
  1193. if( data ){
  1194. alertify.success('글이 삭제되었습니다.');
  1195. boardList();
  1196. }
  1197. },
  1198. error: function(jqXHR, textStatus, errorThrown)
  1199. {
  1200. if( jqXHR.responseText == "timeout" ){
  1201. window.location.href = "/login"
  1202. }else{
  1203. alertify.notify(
  1204. 'Opps!! 글 삭제 과정에 문제가 생겼습니다.',
  1205. 'error', //'error','warning','message'
  1206. 3, //-1
  1207. function(){
  1208. console.log(jqXHR.responseText);
  1209. }
  1210. );
  1211. }
  1212. }
  1213. });
  1214. }
  1215.  
  1216.  
  1217. function boardList(){
  1218. $.ajax(
  1219. {
  1220. type : 'get',
  1221. url : '/board/list',
  1222. dataType : 'json',
  1223. data :
  1224. {
  1225. limit: LIST_ROW_COUNT,
  1226. offset: OFFSET,
  1227. searchWord: SEARCH_WORD
  1228. },
  1229. beforeSend : function(xhr){
  1230. //xhr.setRequestHeader("ApiKey", "asdfasxdfasdfasdf");
  1231. xhr.setRequestHeader("AJAX", true);
  1232. },
  1233. success : function(data, status, xhr) {
  1234.  
  1235. makeListHtml(data);
  1236. },
  1237. error: function(jqXHR, textStatus, errorThrown)
  1238. {
  1239. if( jqXHR.responseText == "timeout" ){
  1240. window.location.href = "/login"
  1241. }else{
  1242. alertify.notify(
  1243. 'Opps!! 글 조회 과정에 문제가 생겼습니다.',
  1244. 'error', //'error','warning','message'
  1245. 3, //-1
  1246. function(){
  1247. console.log(jqXHR.responseText);
  1248. }
  1249. );
  1250. }
  1251. }
  1252. });
  1253. }
  1254.  
  1255. function makeListHtml(list){
  1256.  
  1257. $("#boardTbody").html("");
  1258.  
  1259. //var boardArray = JSON.parse(data); ?? @ResponseBody 자동으로 json 변환
  1260. for( var i=0; i<list.length; i++){
  1261.  
  1262. var boardId = list[i].boardId;
  1263. var userName = list[i].userName;
  1264. var title = list[i].title;
  1265. var content = list[i].content;
  1266. var regDt = list[i].regDt;
  1267. var readCount = list[i].readCount;
  1268.  
  1269. var listHtml =
  1270. '<tr style="cursor:pointer" data-boardId=' + boardId +'><td>' + boardId + '</td><td>' + title + '</td><td>' + userName + '</td><td>' + regDt + '</td><td>' + readCount + '</td></tr>';
  1271.  
  1272. $("#boardTbody").append(listHtml);
  1273. }
  1274.  
  1275.  
  1276. makeListHtmlEventHandler();
  1277.  
  1278. boardListTotalCnt();
  1279. }
  1280.  
  1281. function addPagination(){
  1282.  
  1283. makePaginationHtml(LIST_ROW_COUNT, PAGE_COUNT_PER_BLOCK, CURRENT_PAGE_INDEX, TOTAL_LIST_ITEM_COUNT, "paginationWrapper", boardList );
  1284. }
  1285.  
  1286. function movePage(pageIndex){
  1287. OFFSET = (pageIndex - 1) * LIST_ROW_COUNT;
  1288. CURRENT_PAGE_INDEX = pageIndex;
  1289. boardList();
  1290. }
  1291.  
  1292. function boardListTotalCnt(){
  1293.  
  1294. $.ajax(
  1295. {
  1296. type : 'get',
  1297. url : '/board/list/totalCnt',
  1298. dataType : 'json',
  1299. data :
  1300. {
  1301. searchWord: SEARCH_WORD
  1302. },
  1303. beforeSend : function(xhr){
  1304. //xhr.setRequestHeader("ApiKey", "asdfasxdfasdfasdf");
  1305. xhr.setRequestHeader("AJAX", true);
  1306. },
  1307. success : function(data, status, xhr) {
  1308. TOTAL_LIST_ITEM_COUNT = data;
  1309. addPagination();
  1310. },
  1311. error: function(jqXHR, textStatus, errorThrown)
  1312. {
  1313. if( jqXHR.responseText == "timeout" ){
  1314. window.location.href = "/login"
  1315. }else{
  1316. alertify.notify(
  1317. 'Opps!! 글 전체 갯수 조회 과정에 문제가 생겼습니다.',
  1318. 'error', //'error','warning','message'
  1319. 3, //-1
  1320. function(){
  1321. console.log(jqXHR.responseText);
  1322. }
  1323. );
  1324. }
  1325. }
  1326. });
  1327. }
  1328.  
  1329. // function boardListTotalCnt(){
  1330.  
  1331. // $.ajax(
  1332. // {
  1333. // type : 'get',
  1334. // url : '/board/test',
  1335. // dataType : 'json',
  1336. // beforeSend : function(xhr){
  1337. // //xhr.setRequestHeader("ApiKey", "asdfasxdfasdfasdf");
  1338. // xhr.setRequestHeader("AJAX", true);
  1339. // },
  1340. // success : function(data, status, xhr) {
  1341. // console.log(data);
  1342. // console.log(data.msg);
  1343. // },
  1344. // error: function(jqXHR, textStatus, errorThrown)
  1345. // {
  1346. // if( jqXHR.responseText == "timeout" ){
  1347. // window.location.href = "/login"
  1348. // }else{
  1349. // alertify.notify(
  1350. // 'Opps!! 글 test 에 문제가 생겼습니다.',
  1351. // 'error', //'error','warning','message'
  1352. // 3, //-1
  1353. // function(){
  1354. // console.log(jqXHR.responseText);
  1355. // }
  1356. // );
  1357. // }
  1358. // }
  1359. // });
  1360. // }
  1361.  
  1362. function makeListHtmlEventHandler(){
  1363. $("#boardTbody tr").click(function(){
  1364. var boardId = $(this).attr("data-boardId");
  1365. var userSeq = '<%=userDto.getUserSeq()%>';
  1366. boardDetail(boardId, userSeq);
  1367. //alert(boardId);
  1368. });
  1369. }
  1370.  
  1371. function boardDetail(boardId, userSeq){
  1372.  
  1373. $.ajax(
  1374. {
  1375. type : 'get',
  1376. url : '/board/detail',
  1377. dataType : 'json',
  1378. data :
  1379. {
  1380. boardId: boardId,
  1381. userSeq: userSeq
  1382. },
  1383. beforeSend : function(xhr){
  1384. //xhr.setRequestHeader("ApiKey", "asdfasxdfasdfasdf");
  1385. xhr.setRequestHeader("AJAX", true);
  1386. },
  1387. success : function(data, status, xhr) {
  1388.  
  1389. makeDetailHtml(data);
  1390. },
  1391. error: function(jqXHR, textStatus, errorThrown)
  1392. {
  1393. if( jqXHR.responseText == "timeout" ){
  1394. window.location.href = "/login"
  1395. }else{
  1396. alertify.notify(
  1397. 'Opps!! 글 상세 조회 과정에 문제가 생겼습니다.',
  1398. 'error', //'error','warning','message'
  1399. 3, //-1
  1400. function(){
  1401. console.log(jqXHR.responseText);
  1402. }
  1403. );
  1404. }
  1405. }
  1406. });
  1407. }
  1408.  
  1409. function makeDetailHtml(detail){
  1410.  
  1411. var boardId = detail.boardId;
  1412. var userSeq = detail.userSeq;
  1413. var userName = detail.userName;
  1414. var title = detail.title;
  1415. var content = detail.content;
  1416. var regDt = detail.regDt;
  1417. var readCount = detail.readCount;
  1418. var fileList = detail.fileList;
  1419.  
  1420. $("#boardDetailModal").attr("data-boardId", boardId);
  1421. $("#boardIdDetail").html("#" + boardId);
  1422. $("#titleDetail").html(title);
  1423. $("#contentDetail").html(content);
  1424. $("#userNameDetail").html(userName);
  1425. $("#regDtDetail").html(regDt);
  1426. $("#readCountDetail").html(readCount);
  1427.  
  1428. //FileList
  1429. $("#fileListDetail").html("");
  1430.  
  1431. if( fileList.length > 0 ){
  1432. for(var i=0; i<fileList.length; i++){
  1433. var fileId = fileList[i].fileId;
  1434. var fileName = fileList[i].fileName;
  1435. var fileUrl = fileList[i].fileUrl;
  1436.  
  1437. $("#fileListDetail").append(
  1438. '<span class="fileName">' + fileName + '</span>');
  1439. $("#fileListDetail").append(
  1440. '&nbsp;&nbsp;<a type="button" class="btn btn-outline btn-default btn-xs" ' +
  1441. 'data-fileId="' + fileId + '" ' +
  1442. 'href="' + fileUrl + '" ' +
  1443. 'download="' + fileName + '">내려받기</a>');
  1444. }
  1445. }
  1446.  
  1447. if( userSeq != '<%=userDto.getUserSeq()%>' ){
  1448. $("#btnBoardUpdateForm").hide();
  1449. $("#btnBoardDeleteConfirm").hide();
  1450. }else{
  1451. $("#btnBoardUpdateForm").show();
  1452. $("#btnBoardDeleteConfirm").show();
  1453. }
  1454.  
  1455. $("#boardDetailModal").modal("show");
  1456.  
  1457. makeDetailHtmlEventHandler();
  1458. }
  1459.  
  1460. function makeDetailHtmlEventHandler(){
  1461.  
  1462. }
  1463.  
  1464. </script>
  1465. </body>
  1466. </html>
Advertisement
Add Comment
Please, Sign In to add comment