|
|
@ -13,14 +13,21 @@ import org.springframework.mobile.device.Device;
|
|
|
|
import org.springframework.mobile.device.DeviceUtils;
|
|
|
|
import org.springframework.mobile.device.DeviceUtils;
|
|
|
|
import org.springframework.web.context.request.RequestContextHolder;
|
|
|
|
import org.springframework.web.context.request.RequestContextHolder;
|
|
|
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
|
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.HttpServletRequest;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import javax.xml.bind.JAXBContext;
|
|
|
|
import javax.xml.bind.JAXBContext;
|
|
|
|
import javax.xml.bind.Marshaller;
|
|
|
|
import javax.xml.bind.Marshaller;
|
|
|
|
import javax.xml.bind.Unmarshaller;
|
|
|
|
import javax.xml.bind.Unmarshaller;
|
|
|
|
import java.io.StringReader;
|
|
|
|
import javax.xml.parsers.DocumentBuilder;
|
|
|
|
import java.io.StringWriter;
|
|
|
|
import javax.xml.parsers.DocumentBuilderFactory;
|
|
|
|
|
|
|
|
import javax.xml.parsers.ParserConfigurationException;
|
|
|
|
|
|
|
|
import java.io.*;
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.net.URL;
|
|
|
@ -701,6 +708,88 @@ public class CommUtil {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sql;
|
|
|
|
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<ParameterMapping> parameterMappings = new ArrayList<>(boundSql.getParameterMappings());
|
|
|
|
|
|
|
|
Map<String, Object> 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<Employee> 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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|