@Override
public void signForm(HttpServletResponse response, Map<String, Object> map) {
try{
String substring = url.substring(0, url.indexOf("?"));
String substring1 ="'"+ substring.substring(substring.lastIndexOf("/")+1)+"'";
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment;filename="+new String((System.currentTimeMillis()+".sql").getBytes("utf-8"),"ISO-8859-1"));
OutputStream out = response.getOutputStream();
String name=map.get("name").toString();
String sql0="SHOW CREATE TABLE "+name;
Query query0 = entityManager.createNativeQuery(sql0);
List resultList2 = query0.getResultList();
String s1 = JSON.parseArray(JSON.toJSONString(resultList2.get(0)), String.class).get(1)+";";
out.write((s1+System.getProperty("line.separator")).getBytes());
String sql="SELECT table_name, COLUMN_NAME dbName, DATA_TYPE dbType, COLUMN_COMMENT label FROM INFORMATION_SCHEMA.COLUMNS where table_name=" + "'"+name+"'" + "AND table_schema="+substring1;
Query query = entityManager.createNativeQuery(sql);
List<Object> resultList = query.getResultList();
String insetSql="insert into "+name+" (";
String sql2="SELECT ";
for (Object map1:resultList){
List<String> strings = JSON.parseArray(JSON.toJSONString(map1), String.class);
String s = strings.get(2);
String sd = "`" + strings.get(1) + "`,";
if(s.contains("int")){
sql2+="(`" + strings.get(1) + "`+0) "+strings.get(1)+",";
}else{
sql2+=sd;
}
insetSql+=sd;
}
insetSql=insetSql.substring(0,insetSql.length()-1);
sql2=sql2.substring(0,sql2.length()-1);
insetSql+=" )values";
sql2+=" FROM "+name;
Query query2 = entityManager.createNativeQuery(sql2);
query2.unwrap(SQLQuery.class).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
List<Map<String,Object>> resultList1 = query2.getResultList();
for (Map<String,Object> map1 :resultList1){
String insetSql2=insetSql;
insetSql2+=" ( ";
for (Object map2:resultList){
String s = JSON.parseArray(JSON.toJSONString(map2), String.class).get(1);
String type = JSON.parseArray(JSON.toJSONString(map2), String.class).get(2);
if(type.contains("int")||type.equals("Integer")||map1.get(s)==null){
insetSql2+=map1.get(s)+",";
}else{
insetSql2+="'"+map1.get(s)+"',";
}
}
insetSql2=insetSql2.substring(0,insetSql2.length()-1)+");";
out.write((insetSql2+System.getProperty("line.separator")).getBytes());
}
out.flush();
out.close();
}catch (Exception e){
}
}