diff --git a/build.gradle b/build.gradle index b80b5d3..29fc5aa 100644 --- a/build.gradle +++ b/build.gradle @@ -168,6 +168,10 @@ dependencies { //-----------------------------------------------------------------------------------// runtimeOnly 'com.h2database:h2:1.4.199' // 2.0.202 사용시 에러 발생 implementation 'org.postgresql:postgresql:42.3.1' + + // https://mvnrepository.com/artifact/commons-beanutils/commons-beanutils + implementation group: 'commons-beanutils', name: 'commons-beanutils', version: '1.9.4' + //-----------------------------------------------------------------------------------// //-----------------------------------------------------------------------------------// diff --git a/src/main/java/com/xit/core/util/CommUtil.java b/src/main/java/com/xit/core/util/CommUtil.java index 17101b7..75bc38e 100644 --- a/src/main/java/com/xit/core/util/CommUtil.java +++ b/src/main/java/com/xit/core/util/CommUtil.java @@ -13,14 +13,21 @@ import org.springframework.mobile.device.Device; import org.springframework.mobile.device.DeviceUtils; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.xml.bind.JAXBContext; import javax.xml.bind.Marshaller; import javax.xml.bind.Unmarshaller; -import java.io.StringReader; -import java.io.StringWriter; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import java.io.*; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.URL; @@ -701,6 +708,88 @@ public class CommUtil { } return sql; } + + /** + * + * @param sqlSession SqlSessionTemplate + * @param id SQL id + * @param param Object + */ + public static String getXmlSql(SqlSession sqlSession, String id, Object param) { + + BoundSql boundSql = sqlSession.getConfiguration().getMappedStatement(id).getBoundSql(param); + + List parameterMappings = new ArrayList<>(boundSql.getParameterMappings()); + Map parameters = new HashMap<>(); + if (param instanceof Map) { + parameters.putAll((Map) param); + } else { + for (ParameterMapping parameterMapping : parameterMappings) { + try { + String field = parameterMapping.getProperty(); + //try { + String methodNm = "get"+field.substring(0,1).toUpperCase()+field.substring(1); + Method method = param.getClass().getMethod(methodNm); + + parameters.put(field, method.invoke(param)); + //parameters.put(field, param.getClass().getMethod("get"+field.substring(0,1).toUpperCase()+field.substring(1)).invoke(param)); + + } catch (NoSuchMethodException e) { + e.printStackTrace(); + throw new RuntimeException(e); + } catch (InvocationTargetException | IllegalAccessException e) { + throw new RuntimeException(e); + } + } + } + + String sql = boundSql.getSql(); + + for (ParameterMapping par : parameterMappings) { + Object parameter = parameters.get(par.getProperty()); + + if (parameter == null) + sql = sql.replaceFirst("\\?", "NULL"); + else + sql = sql.replaceFirst("\\?", "'" + parameter.toString() + "'"); + } + return sql; + } + + public static String getXmlSql(String xmlFileName, String nodeName) { + String sql = null; + + try { + + ClassLoader classloader = Thread.currentThread().getContextClassLoader(); + InputStream is = classloader.getResourceAsStream("test.csv"); + + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + //builder.p + Document document = builder.parse(is); + //Document document = builder.parse(new File(xmlFileName)); + + //List employees = new ArrayList<>(); + NodeList nodeList = document.getDocumentElement().getChildNodes(); + + + for (int i = 0; i < nodeList.getLength(); i++) { + Node node = nodeList.item(i); + if (node.getNodeType() == Node.ELEMENT_NODE) { + Element elem = (Element) node; + return elem.getElementsByTagName(nodeName) + .item(0).getChildNodes().item(0).getNodeValue(); + + } + } + return sql; + + + } catch (ParserConfigurationException | IOException | SAXException e) { + throw new RuntimeException(e); + } + } } diff --git a/src/main/java/com/xit/core/util/mpower/MpowerUtils.java b/src/main/java/com/xit/core/util/mpower/MpowerUtils.java index 9f84165..8ebc4cd 100644 --- a/src/main/java/com/xit/core/util/mpower/MpowerUtils.java +++ b/src/main/java/com/xit/core/util/mpower/MpowerUtils.java @@ -2,7 +2,17 @@ package com.xit.core.util.mpower; import com.plf.client.Client; import lombok.extern.slf4j.Slf4j; - +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import java.io.File; +import java.io.IOException; import java.sql.*; import java.util.ArrayList; import java.util.HashMap; @@ -450,4 +460,5 @@ public class MpowerUtils { + } diff --git a/src/main/resources/config/application-dev.yml b/src/main/resources/config/application-dev.yml index 0d0965c..727cc63 100644 --- a/src/main/resources/config/application-dev.yml +++ b/src/main/resources/config/application-dev.yml @@ -21,12 +21,12 @@ spring: # ================================================================================================================== datasource: driver-class-name: oracle.jdbc.OracleDriver -# url: jdbc:oracle:thin:@211.119.124.118:1521:bustms -# username: traffic -# password: xhdgkq0 - url: ENC(Du4NMmmioRvKPEusb8MiTTvNaXVoTItupOvD6qDhkeJv8vJKgdQuYR1pfx6EiejdZxw42ihrilk=) - username: ENC(MtR2JPkVe/qAf4+4ov5Oaw==) - password: ENC(6DJ2lcMsftlVjv1Ddc4d2w==) + url: jdbc:oracle:thin:@211.119.124.118:1521:bustms + username: traffic + password: xhdgkq0 +# url: ENC(Du4NMmmioRvKPEusb8MiTTvNaXVoTItupOvD6qDhkeJv8vJKgdQuYR1pfx6EiejdZxw42ihrilk=) +# username: ENC(MtR2JPkVe/qAf4+4ov5Oaw==) +# password: ENC(6DJ2lcMsftlVjv1Ddc4d2w==) hikari: driver-class-name: ${spring.datasource.driver-class-name} jdbc-url: ${spring.datasource.url} diff --git a/src/main/resources/config/conf.yml b/src/main/resources/config/conf.yml index 2f77382..3d295c9 100644 --- a/src/main/resources/config/conf.yml +++ b/src/main/resources/config/conf.yml @@ -17,7 +17,7 @@ api: file: cmm: upload: - root: /data/file/upload + root: c:/data/file/upload # root: /Users/minuk/data/file/upload # 공지사항 path: /kangnamSIM/simUpFile diff --git a/src/main/resources/mybatis-mapper/biz/ctgy/board2-mapper.xml b/src/main/resources/mybatis-mapper/biz/ctgy/board2-mapper.xml new file mode 100644 index 0000000..1bdd13c --- /dev/null +++ b/src/main/resources/mybatis-mapper/biz/ctgy/board2-mapper.xml @@ -0,0 +1,32 @@ + + + + \ No newline at end of file