묻고답하기, XML변환 개발 (중간백업)

This commit is contained in:
KNKIM 2021-07-20 22:11:30 +09:00
parent 1cc5bf4fc1
commit e34595f784
14 changed files with 420 additions and 32 deletions

View File

@ -0,0 +1,94 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!-- uac.service.board.qna_GET.xml -->
<result>
<code>S</code>
<message>성공적으로 조회되었습니다.</message>
<records>10</records>
<page>1</page>
<totPages>15</totPages>
<record>
<noticeNo>1</noticeNo>
<noticeType>101</noticeType>
<title>공지사항 테스트</title>
<readCount>55</readCount>
<regDate>2021-07-19</regDate>
</record>
<record>
<noticeNo>2</noticeNo>
<noticeType>101</noticeType>
<title>공지사항 테스트</title>
<readCount>55</readCount>
<regDate>2021-07-19</regDate>
</record>
<record>
<noticeNo>3</noticeNo>
<noticeType>101</noticeType>
<title>공지사항 테스트</title>
<readCount>55</readCount>
<regDate>2021-07-19</regDate>
</record>
<record>
<noticeNo>4</noticeNo>
<noticeType>101</noticeType>
<title>공지사항 테스트</title>
<readCount>55</readCount>
<regDate>2021-07-19</regDate>
</record>
<record>
<noticeNo>5</noticeNo>
<noticeType>101</noticeType>
<title>공지사항 테스트</title>
<readCount>55</readCount>
<regDate>2021-07-19</regDate>
</record>
<record>
<noticeNo>6</noticeNo>
<noticeType>101</noticeType>
<title>공지사항 테스트</title>
<readCount>55</readCount>
<regDate>2021-07-19</regDate>
</record>
<record>
<noticeNo>7</noticeNo>
<noticeType>101</noticeType>
<title>공지사항 테스트</title>
<readCount>55</readCount>
<regDate>2021-07-19</regDate>
</record>
<record>
<noticeNo>8</noticeNo>
<noticeType>101</noticeType>
<title>공지사항 테스트</title>
<readCount>55</readCount>
<regDate>2021-07-19</regDate>
</record>
<record>
<noticeNo>9</noticeNo>
<noticeType>101</noticeType>
<title>공지사항 테스트</title>
<readCount>55</readCount>
<regDate>2021-07-19</regDate>
</record>
<record>
<noticeNo>10</noticeNo>
<noticeType>101</noticeType>
<title>공지사항 테스트</title>
<readCount>55</readCount>
<regDate>2021-07-19</regDate>
</record>
<record>
<noticeNo>11</noticeNo>
<noticeType>101</noticeType>
<title>공지사항 테스트</title>
<readCount>55</readCount>
<regDate>2021-07-19</regDate>
</record>
<record>
<noticeNo>12</noticeNo>
<noticeType>101</noticeType>
<title>공지사항 테스트</title>
<readCount>55</readCount>
<regDate>2021-07-19</regDate>
</record>
</result>

View File

@ -4,6 +4,28 @@ package nlib.bbs.service;
import nlib.restful.service.DataApiReqVO; import nlib.restful.service.DataApiReqVO;
import nlib.restful.service.DataApiResVO; import nlib.restful.service.DataApiResVO;
/**
* <pre>
* @Class Name : BoardService.java
*
* @Description : 게시물 관리 클래스
*
*
* @프로젝트명: 지방문화원 통합자료관리시스템 구축사업 (2021)
*
* </pre>
*
* @ ------------ -------- ---------------------------
* @ 수정일 수정자 수정내용
* @ ------------ -------- ---------------------------
* @ 2021. 7. 19. KNKIM 최초 생성
*
*
* @author 이씨플라자 * DIGITALSHIP KNKIM
* @since 2021. 7. 19.
* @version 1.0
*
*/
public interface BoardService public interface BoardService
{ {
public DataApiResVO listNotices(DataApiReqVO reqVO); public DataApiResVO listNotices(DataApiReqVO reqVO);
@ -12,6 +34,12 @@ public interface BoardService
public DataApiResVO listFAQs(DataApiReqVO reqVO); public DataApiResVO listFAQs(DataApiReqVO reqVO);
/**
* 묻고답하기 목록 조회한다.
*
* @param reqVO
* @return
*/
public DataApiResVO listQnAs(DataApiReqVO reqVO); public DataApiResVO listQnAs(DataApiReqVO reqVO);
public DataApiResVO selectQnA(DataApiReqVO reqVO); public DataApiResVO selectQnA(DataApiReqVO reqVO);

View File

@ -14,7 +14,12 @@ import nlib.restful.service.DataApiResVO;
public class BoardDAO extends DataApi public class BoardDAO extends DataApi
{ {
private static final Logger log = LoggerFactory.getLogger(BoardDAO.class); private static final Logger log = LoggerFactory.getLogger(BoardDAO.class);
/**
* 자원의 URI
*/
public static final String RESOURCE_URI = "/uac/service/board/qna";
public DataApiResVO listNotices(DataApiReqVO reqVO) { public DataApiResVO listNotices(DataApiReqVO reqVO) {
return null; return null;
} }
@ -27,8 +32,15 @@ public class BoardDAO extends DataApi
return null; return null;
} }
/**
* 묻고답하기 목록 조회한다.
*
* @param reqVO
* @return
*/
public DataApiResVO listQnAs(DataApiReqVO reqVO) { public DataApiResVO listQnAs(DataApiReqVO reqVO) {
return null; reqVO.setReqUrl(RESOURCE_URI + "/list");
return get(reqVO);
} }
public DataApiResVO selectQnA(DataApiReqVO reqVO) { public DataApiResVO selectQnA(DataApiReqVO reqVO) {

View File

@ -32,8 +32,14 @@ public class BoardServiceImpl implements BoardService
return null; return null;
} }
/*
* 묻고답하기 목록 조회한다.
*
* (non-Javadoc)
* @see nlib.bbs.service.BoardService#listQnAs(nlib.restful.service.DataApiReqVO)
*/
public DataApiResVO listQnAs(DataApiReqVO reqVO) { public DataApiResVO listQnAs(DataApiReqVO reqVO) {
return null; return boardDAO.listQnAs(reqVO);
} }
public DataApiResVO selectQnA(DataApiReqVO reqVO) { public DataApiResVO selectQnA(DataApiReqVO reqVO) {

View File

@ -1,32 +1,40 @@
package nlib.bbs.web; package nlib.bbs.web;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.Map;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import egovframework.com.cmm.service.FileVO;
import nlib.bbs.service.BoardService; import nlib.bbs.service.BoardService;
import nlib.cmm.NlibCommonController;
import nlib.restful.service.DataApiReqVO;
import nlib.restful.service.DataApiResVO;
@Controller @Controller
public class BoardController public class BoardController extends NlibCommonController
{ {
private static final Logger log = LoggerFactory.getLogger(BoardController.class); private static final Logger log = LoggerFactory.getLogger(BoardController.class);
@Resource(name = "boardService") @Resource(name = "boardService")
private BoardService boardService; private BoardService boardService;
@Autowired
private AuthenticationManager authenticationManager;
/** /**
* 공지사항 목록 조회한다. * 공지사항 목록 조회한다.
@ -34,8 +42,10 @@ public class BoardController
* @param req * @param req
* @return * @return
*/ */
@SuppressWarnings("deprecation")
@RequestMapping("/board/listNotices.do") @RequestMapping("/board/listNotices.do")
public String listNotices(HttpServletRequest req) { public String listNotices(HttpServletRequest req) {
return "nlib/board/listNotices"; return "nlib/board/listNotices";
} }
@ -61,16 +71,56 @@ public class BoardController
} }
/** /**
* 묻고답하기 목록 조회한다. * 묻고답하기 목록 조회 화면을 구성한다.
* *
* @param req * @param req
* @return * @return
*/ */
@RequestMapping("/board/listQnAs.do") @RequestMapping("/board/listQnAs.do")
public String listQnAs(HttpServletRequest req) { public String listQnAs(HttpServletRequest req, Authentication authentication, @RequestParam Map<String, String> commandMap, ModelMap model) {
return "nlib/board/listQnAs"; return "nlib/board/listQnAs";
} }
/**
* 묻고답하기 목록 조회한다.
*
* @param req
* @return
*/
@RequestMapping(value="/board/listQnAsAjax.do")
public ResponseEntity<String> listQnAsAjax(HttpServletRequest req,
Authentication authentication, @RequestBody Map<String, String> paramMap) {
String searchKeyword = paramMap.get("searchKeyword");
String pageNo = paramMap.get("pageNo");
String pageRows = paramMap.get("pageRows");
log.debug("listQnAs > pageNo = " + pageNo);
log.debug("listQnAs > pageRows = " + pageRows);
log.debug("listQnAs > keyword = " + searchKeyword);
//-------------------------------
// REQ VO 구성
//-------------------------------
DataApiReqVO reqVO = new DataApiReqVO();
reqVO.setAuthKey(getAuthKey(authentication));
reqVO.setPageNo(pageNo);
reqVO.setPageRows(pageRows);
// 추가 정보 설정
HashMap<String, Object> info = new HashMap<String, Object>();
info.put("keyword", searchKeyword);
reqVO.setInfo(info);
// 요청
DataApiResVO resVO = boardService.listQnAs(reqVO);
// JSON변환 응답 처리
return makeResponseEntityJson(resVO);
}
/** /**
* 묻고답하기 상세 내용 조회한다. * 묻고답하기 상세 내용 조회한다.
* *

View File

@ -0,0 +1,64 @@
package nlib.cmm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import nlib.bbs.web.BoardController;
import nlib.cmm.exception.ErrorMessage;
import nlib.restful.service.DataApiResVO;
import nlib.security.SecUserVO;
import nlib.user.service.NlibLoginVO;
public class NlibCommonController {
private static final Logger log = LoggerFactory.getLogger(BoardController.class);
static final String ANONYMOUS_AUTH_KEY = "ANONYMOUS_AUTH_KEY_NONE";
public NlibLoginVO getNlibLoginVO(Authentication authentication) {
if(authentication == null) return null;
return (NlibLoginVO)authentication.getPrincipal();
}
public SecUserVO getSecLoginVO(Authentication authentication) {
if(authentication == null) return null;
return (SecUserVO)authentication.getPrincipal();
}
public String getAuthKey(Authentication authentication) {
if(authentication == null) return ANONYMOUS_AUTH_KEY;
return ((NlibLoginVO)authentication.getPrincipal()).getAuthKey();
}
public ResponseEntity<String> makeResponseEntityJson(DataApiResVO resVO) {
// Convert Json
ObjectMapper mapper = new ObjectMapper();
String jsonStr = null;
HttpHeaders headers = new HttpHeaders();
headers.add(HttpHeaders.CONTENT_TYPE, "application/json; charset=UTF-8");
try {
jsonStr = mapper.writeValueAsString(resVO);
log.debug("RETURN DATA > json:" + jsonStr);
} catch (JsonProcessingException e) {
ErrorMessage eMsg = new ErrorMessage("ERR_JSON_CONVERT", "응답객체를 JSON으로 변환 처리 중 오류가 발생하였습니다. : " + e.toString());
try { jsonStr = mapper.writeValueAsString(eMsg); } catch (JsonProcessingException ee) {}
e.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).headers(headers).body(jsonStr);
}
return ResponseEntity.ok().headers(headers).body(jsonStr);
}
}

View File

@ -26,7 +26,7 @@ import nlib.util.StringUtil;
* </pre> * </pre>
* *
* @ ------------ -------- --------------------------- * @ ------------ -------- ---------------------------
* @ 수정일 수정자 수정내용 * @ 수정일 수정자 수정내용
* @ ------------ -------- --------------------------- * @ ------------ -------- ---------------------------
* @ 2021. 7. 9. KNKIM 최초 생성 * @ 2021. 7. 9. KNKIM 최초 생성
* *
@ -114,6 +114,11 @@ public interface DataApiInterface {
} }
} }
// 요청 파라메타 확인
for(String key : map.keySet()) {
log.debug("MultiValueMap > " + key + "=" + map.get(key));
}
return map; return map;
} }

View File

@ -0,0 +1,79 @@
package nlib.restful.service;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.HashMap;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent;
public class XmlConverter {
@SuppressWarnings("restriction")
public static void main(String argv[]) {
String inputFile = "C:/iams/workspace/nlib/data/dataxml/uac.service.board.qna.list_GET.xml";
HashMap<String, String> resMap = new HashMap<String, String>();
try {
// First create a new XMLInputFactory
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
// Setup a new eventReader
InputStream in = new FileInputStream(inputFile);
XMLEventReader eventReader = inputFactory.createXMLEventReader(in);
// Read the XML document
int depth = 0;
StartElement startElement = null;
while (eventReader.hasNext()) {
XMLEvent event = eventReader.nextEvent();
System.out.println(" -> " + event);
String elementName = null;
String elementValue = null;
HashMap<String, String> elementValues = null;
if (event.isStartElement()) {
startElement = event.asStartElement();
if (startElement.getName().getLocalPart().equals("result")) {
depth++;
event = eventReader.nextEvent();
System.out.println(" > " + event);
// result의 하위 엘리먼트 시작 찾기
while (!event.isStartElement()) {
event = eventReader.nextEvent();
System.out.println(" 하위엘리먼트 시작전: " + event);
}
while (!event.isEndElement()) {
if (event.isCharacters()) {
String content = event.asCharacters().getData();
System.out.println("content: -" + content + "_");
}
event = eventReader.nextEvent();
System.out.println(" >> " + event);
}
event = eventReader.nextEvent();
System.out.println(" >>> " + event);
continue;
}
}
}
} catch (FileNotFoundException e) {
System.out.println("File not Found: " + inputFile);
} catch (XMLStreamException e) {
e.printStackTrace();
}
}
}

View File

@ -2,9 +2,12 @@
<beans <beans
xmlns="http://www.springframework.org/schema/beans" xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context" xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation=" xsi:schemaLocation="
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context
@ -71,5 +74,4 @@
</bean> </bean>
<alias name="spring.RegularCommonsMultipartResolver" alias="multipartResolver" /> <alias name="spring.RegularCommonsMultipartResolver" alias="multipartResolver" />
</beans> </beans>

View File

@ -2,10 +2,10 @@
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd"> xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">
<bean id="beanValidator" class="org.springmodules.validation.commons.DefaultBeanValidator"> <!-- <bean id="beanValidator" class="org.springmodules.validation.commons.DefaultBeanValidator">
<property name="validatorFactory" ref="validatorFactory"/> <property name="validatorFactory" ref="validatorFactory"/>
</bean> </bean> -->
<!--
<bean id="validatorFactory" class="org.springmodules.validation.commons.DefaultValidatorFactory"> <bean id="validatorFactory" class="org.springmodules.validation.commons.DefaultValidatorFactory">
<property name="validationConfigLocations"> <property name="validationConfigLocations">
<list> <list>
@ -13,6 +13,6 @@
<value>/WEB-INF/config/egovframework/validator/validator.xml</value> <value>/WEB-INF/config/egovframework/validator/validator.xml</value>
</list> </list>
</property> </property>
</bean> </bean> -->
</beans> </beans>

View File

@ -16,7 +16,7 @@
<Logger name="jdbc.sqltiming" level="INFO" additivity="false"> <Logger name="jdbc.sqltiming" level="INFO" additivity="false">
<AppenderRef ref="console" /> <AppenderRef ref="console" />
</Logger> </Logger>
<Logger name="org.springframework" level="INFO" additivity="false"> <Logger name="org.springframework" level="DEBUG" additivity="false">
<AppenderRef ref="console" /> <AppenderRef ref="console" />
</Logger> </Logger>
<Root level="DEBUG"> <Root level="DEBUG">

View File

@ -30,6 +30,7 @@
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="validator" uri="http://www.springmodules.org/tags/commons-validator" %> <%@ taglib prefix="validator" uri="http://www.springmodules.org/tags/commons-validator" %>
<c:set var="pageTitle">묻고답하기</c:set> <c:set var="pageTitle">묻고답하기</c:set>
<!DOCTYPE html> <!DOCTYPE html>
@ -41,22 +42,37 @@
<link type="text/css" rel="stylesheet" href="/nlib/js/jsgrid/nlib-jsgrid.css" /> <link type="text/css" rel="stylesheet" href="/nlib/js/jsgrid/nlib-jsgrid.css" />
<link type="text/css" rel="stylesheet" href="/nlib/js/jsgrid/nlib-jsgrid-theme.css" /> <link type="text/css" rel="stylesheet" href="/nlib/js/jsgrid/nlib-jsgrid-theme.css" />
<script src="/nlib/js/jsgrid/nlib-jsgrid.js"></script> <script src="/nlib/js/jsgrid/nlib-jsgrid.js"></script>
</head> </head>
<body> <body onload="fn_init()">
<h1>묻고답하기</h1> <h1>묻고답하기</h1>
<form:form commandName="reqInfo" <form name="articleForm"
action="${pageContext.request.contextPath}/board/listQnAs.do" action="${pageContext.request.contextPath}/board/listQnAs.do"
method="post" method="post"
target="_blank"> onSubmit="fn_search_article(); return false;">
<!-- 검색조건 -->
<select name="pageRows" id="pageRows" title="목록에 보여줄 글 개수">
<option value="10">10개씩 보기</option>
<option value="50">50개씩 보기</option>
<option value="100">100개씩 보기</option>
</select>
<input type="text" name="pageNo" id="pageNo" title="페이지번호" value="1" size="5" maxlength="5" />
<input type="text" name="searchKeyword" id="searchKeyword" title="검색어" value="" size="35" maxlength="50" />
<input type="submit" name="btnSearch" id="btnSearch" value="검색" />
<input type="button" name="btnNew" id="btnNew" value="글쓰기" <input type="button" name="btnNew" id="btnNew" value="글쓰기"
onclick="javascript:location.href='${pageContext.request.contextPath}/board/insertQnAForm.do';" /> onclick="javascript:location.href='${pageContext.request.contextPath}/board/insertQnAForm.do';" />
<div id="jsGrid" name="jsGrid" ></div> <div id="jsGrid" name="jsGrid" ></div>
</form:form>
</form>
<script type="text/javaScript" language="javascript"> <script type="text/javaScript" language="javascript">
// 그리드 데이터 // 그리드 데이터
@ -138,10 +154,42 @@ $("#jsGrid").jsGrid({
{ title:"번호", name: "noticeNo" , type: "number" , width: 50, align: "center"}, { title:"번호", name: "noticeNo" , type: "number" , width: 50, align: "center"},
{ title:"유형", name: "noticeType", type: "select", width: 80, align: "center", items: noticeTypes, valueField: "Id", textField: "Name" }, { title:"유형", name: "noticeType", type: "select", width: 80, align: "center", items: noticeTypes, valueField: "Id", textField: "Name" },
{ title:"제목", name: "title", type: "text" , width: 200, align: "left" }, { title:"제목", name: "title", type: "text" , width: 200, align: "left" },
{ title:"조회수", name: "readCount", type: "number", width: 50, align: "center" }, { title:"조회수", name: "readCount", type: "number", width: 50, align: "center" },
{ title:"등록일", name: "regDate", type: "text", width: 100, align: "center"} { title:"등록일", name: "regDate", type: "text", width: 100, align: "center"}
] ]
}); });
function fn_search_article() {
var searchKeyword = document.articleForm.searchKeyword.value;
var pageNo = document.articleForm.pageNo.value;
var pageRows = document.articleForm.pageRows.value;
var inputData = {
"searchKeyword" : searchKeyword /*encodeURIComponent(searchKeyword)*/
, "pageNo" : pageNo
, "pageRows": pageRows};
//lert(JSON.stringify(inputData));
$.ajax({
url:"${pageContext.request.contextPath}/board/listQnAsAjax.do",
contentType: "application/json; charset=utf-8", /* */
type: "post",
data: JSON.stringify(inputData),
dataType:'json', /* Server Response Data Type */
success: function(returnData, status){
alert("returnData=" + JSON.stringify(returnData));
},
error: function(data){
alert("조회에 실패하였습니다.\n" + data.code + " : " + data.message);
}
});
}
function fn_init() {
fn_search_article();
document.articleForm.searchKeyword.focus();
}
</script> </script>
</body> </body>

View File

@ -16,7 +16,7 @@
<Logger name="jdbc.sqltiming" level="INFO" additivity="false"> <Logger name="jdbc.sqltiming" level="INFO" additivity="false">
<AppenderRef ref="console" /> <AppenderRef ref="console" />
</Logger> </Logger>
<Logger name="org.springframework" level="INFO" additivity="false"> <Logger name="org.springframework" level="DEBUG" additivity="false">
<AppenderRef ref="console" /> <AppenderRef ref="console" />
</Logger> </Logger>
<Root level="DEBUG"> <Root level="DEBUG">

View File

@ -1,5 +1,5 @@
Manifest-Version: 1.0 Manifest-Version: 1.0
Built-By: KNKIM Built-By: KNKIM
Build-Jdk: 1.8.0_291 Build-Jdk: 1.8.0_291
Created-By: Maven Integration for Eclipse Created-By: Maven Integration for Eclipse