jsp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> <c:set var="ctp" value="${pageContext.request.contextPath}"/> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>qrCodePractice.jsp</title> <jsp:include page="/WEB-INF/views/include/bs4.jsp"></jsp:include> <script> 'use strict'; function qrCreate(no) { let movie = $("#movie").val(); let adult = $("#adult").val(); let student = $("#student").val(); if(adult == '' && student == '') { alert("인원을 설정해주세요!"); return; } let query = { movie: movie, adult: adult, student: student } $.ajax({ type: "post", url : "${ctp}/study/qrCodePractice", data: query, success: function(res) { location.reload(); }, error : function() { alert("전송 오류"); } }); } function searchCheck() { let searchWord = $("#searchWord").val(); let part = $("#part").val(); if(searchWord.trim == '') { return; } location.href = '${ctp}/study/qrCodePractice?searchWord='+searchWord+'&part='+part+'&pag=${pageVO.pag}' } </script> </head> <body> <jsp:include page="/WEB-INF/views/include/nav.jsp" /> <jsp:include page="/WEB-INF/views/include/slide2.jsp" /> <p><br/></p> <div class="container mb-2"> <b>검색 : </b> <select name="part" id="part"> <option ${pageVO.part =='idx' ? 'selected' : '' } value="idx">표번호</option> <option ${pageVO.part =='qrCode' ? 'selected' : '' } value="qrCode">qr코드</option> <option ${pageVO.part =='bigo' ? 'selected' : '' } value="bigo">내용</option> </select> <input type="text" name="searchWord" id="searchWord" value="${searchWord}"/> <input type="button" value="검색" xxonclick="searchCheck()" class="btn btn-secondary btn-sm" /> </div> <div class="container"> <table class="table text-center"> <tr> <th>표번호</th> <th>내용</th> <th>qr코드</th> <th>표생성일</th> </tr> <c:forEach var="vo" items="${vos}" varStatus="st"> <tr> <td style="vertical-align: middle;">${vo.idx}</td> <td style="vertical-align: middle;">${vo.bigo}</td> <td><img src="${ctp}/data/qrCode/practice/${vo.qrCode}.png"/></td> <td style="vertical-align: middle;"><fmt:formatDate value="${vo.qrDate}" pattern="yyyy년 MM월 dd일"/></td> </tr> </c:forEach> <tr><td colspan="4"></td></tr> </table> <c:if test="${searchWord == sMid && pageVO.part == qrCode}"> <c:set var="ctp_qrList" value="${ctp}/study/qrCodePractice?" /> </c:if> <c:if test="${searchWord != sMid || pageVO.part != qrCode}"> <c:set var="ctp_qrList" value="${ctp}/study/qrCodePractice?searchWord=${searchWord}&part=${pageVO.part}&" /> </c:if> <div class="text-center"> <ul class="pagination justify-content-center"> <c:if test="${pageVO.pag > 1}"> <li class="page-item"><a class="page-link text-secondary" href="${ctp_qrList}pag=1">첫페이지</a></li> </c:if> <c:if test="${pageVO.curBlock > 0}"> <li class="page-item"><a class="page-link text-secondary" href="${ctp_qrList}pag=${(pageVO.curBlock-1)*pageVO.blockSize + 1}">이전블록</a></li> </c:if> <c:forEach var="i" begin="${(pageVO.curBlock)*pageVO.blockSize + 1}" end="${(pageVO.curBlock)*pageVO.blockSize + pageVO.blockSize}" varStatus="st"> <c:if test="${i <= pageVO.totPage && i == pageVO.pag}"> <li class="page-item active"><a class="page-link bg-secondary border-secondary" href="${ctp_qrList}pag=${i}">${i}</a></li> </c:if> <c:if test="${i <= pageVO.totPage && i != pageVO.pag}"> <li class="page-item"><a class="page-link text-secondary" href="${ctp_qrList}pag=${i}">${i}</a></li> </c:if> </c:forEach> <c:if test="${pageVO.curBlock < pageVO.lastBlock}"> <li class="page-item"><a class="page-link text-secondary" href="${ctp_qrList}pag=${(pageVO.curBlock+1)*pageVO.blockSize + 1}">다음블록</a></li> </c:if> <c:if test="${pageVO.pag < pageVO.totPage}"> <li class="page-item"><a class="page-link text-secondary" href="${ctp_qrList}pag=${pageVO.totPage}">마지막페이지</a></li> </c:if> </ul> </div> </div> <div class="container"> <h2>영화 예매</h2> <div> 영화 : <select name="movie" id="movie" class="mb-2"> <option value="아바타">아바타</option> <option value="슬램덩크">슬램덩크</option> <option value="영웅">영웅</option> <option value="짱구는 못말려">짱구는 못말려</option> <option value="더복서">더복서</option> <option value="밀정">밀정</option> </select><br/> 인원 : 성인 <select name="adult" id="adult"> <option value="">인원선택</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> </select> 청소년 <select name="student" id="student"> <option value="">인원선택</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> </select><br/> <input type="button" value="예매하기" xxonclick="qrCreate()" class="btn btn-info mt-2" /> </div> </div> <p><br/></p> <jsp:include page="/WEB-INF/views/include/footer.jsp" /> </body> </html> | cs |
컨트롤러
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | // QR Code 작성 폼 @RequestMapping(value = "/qrCodePractice", method = RequestMethod.GET) public String qrCodePracticeGet(HttpSession session, Model model, PageVO pageVO, String searchWord) { if(pageVO.getPart() == null) pageVO.setPart("qrCode"); if(searchWord == null) searchWord = ""; ArrayList<QrCodeVO> vos = new ArrayList<QrCodeVO>(); ObjectMapper objectMapper = new ObjectMapper(); ArrayList<HashMap<String, Object>> listMap = pageProcess.paging(pageVO, model, "qrCode", pageVO.getPart(), searchWord); for(int i=0; i<listMap.size(); i++) vos.add(objectMapper.convertValue(listMap.get(i), QrCodeVO.class)); System.out.println(vos); model.addAttribute("vos",vos); return "study/qrCode/qrCodePractice"; } // QR Code 생성 @ResponseBody @RequestMapping(value = "/qrCodePractice", method = RequestMethod.POST) public String qrCodePracticePost(HttpSession session,HttpServletRequest request, String movie, String adult, String student) { String mid = (String) session.getAttribute("sMid"); String realPath = request.getSession().getServletContext().getRealPath("/resources/data/qrCode/practice/"); int res = studyService.qrCodePracticeCreate(mid,movie,adult,student,realPath); return res+""; } | cs |
서비스
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | @Override public int qrCodePracticeCreate(String mid, String movie, String adult, String student, String realPath) { String qrCodeName = ""; SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmssSSSS"); qrCodeName = sdf.format(new Date()) + mid + adult + student; SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy년 MM월 dd일"); String content = "영화정보 : " + movie + " - 예매일 : " + sdf2.format(new Date()) + " - 성인 : " + adult + ", 청소년 : " + student; try { File file = new File(realPath); if(!file.exists()) file.mkdirs(); String qrContent = new String(content.getBytes("UTF-8"), "ISO-8859-1"); int qrCodeColor = 0xFF000000; int qrCodeBackColor = 0xFFFFFFFF; QRCodeWriter qrCodeWriter = new QRCodeWriter(); BitMatrix bitMatrix = qrCodeWriter.encode(qrContent, BarcodeFormat.QR_CODE, 200, 200); MatrixToImageConfig matrixToImageConfig = new MatrixToImageConfig(qrCodeColor,qrCodeBackColor); BufferedImage bufferedImage = MatrixToImageWriter.toBufferedImage(bitMatrix, matrixToImageConfig); ImageIO.write(bufferedImage, "png", new File(realPath + qrCodeName + ".png")); } catch (IOException e) { e.printStackTrace(); } catch (WriterException e) { e.printStackTrace(); } content = "영화정보 : " + movie + " - 예매일 : " + sdf2.format(new Date()); QrCodeVO vo = new QrCodeVO(); vo.setQrCode(qrCodeName); vo.setBigo(content); return studyDAO.setQrCode(vo); } | cs |
매퍼
1 2 3 | <insert id="setQrCode"> insert into qrCode values(default,#{vo.qrCode},#{vo.bigo},default); </insert> | cs |
테이블 구조
1 2 3 4 5 6 | create table qrCode( idx int not null auto_increment primary key, qrCode varchar(200) not null, bigo varchar(200), qrDate datetime default now() ); | cs |
첫댓글 다양한 방법으로 잘 처리 하셨습니다.
작성된 QR코드를 찍어보니 영화정보가 깔끔하게 잘 들어있군요. 수고하셨습니다.