(同一个pojo)的时候两次解析格式不同,数据差别不打,但是就是格式不同?
有@ResponseBody注解,直接返回map, 把list设置到map里面。
public abstract class BaseDaoImpl {
private static DruidDataSource ds = null;
public BaseDaoImpl() {
}
private static InputStream getPropertiesInputStream() {
return BaseDaoImpl.class.getClassLoader().getResourceAsStream("conf/mysql.properties");
}
public static Date toDate(java.util.Date d) {
return new Date(d.getTime());
}
public static Timestamp toTimestamp(java.util.Date d) {
return new Timestamp(d.getTime());
}
public Connection getConn() {
try {
Connection con = ds.getConnection();
return con;
} catch (SQLException var2) {
throw new RuntimeException(var2);
}
}
public void closeAll(Connection conn, Statement stmt, ResultSet rs) {
Exception ex1 = null;
Exception ex2 = null;
Exception ex3 = null;
if (rs != null) {
try {
rs.close();
} catch (SQLException var10) {
ex1 = var10;
var10.printStackTrace();
}
}
if (stmt != null) {
try {
stmt.close();
} catch (SQLException var9) {
ex2 = var9;
var9.printStackTrace();
}
}
if (conn != null) {
try {
if (!conn.isClosed()) {
conn.close();
}
} catch (SQLException var8) {
ex3 = null;
var8.printStackTrace();
}
}
if (ex1 != null || ex2 != null || ex3 != null) {
throw new RuntimeException("数据库关闭环节失败" + (ex1 != null ? ex1.getMessage() : "") + (ex2 != null ? ex2.getMessage() : "") + (ex3 != null ? ((Exception)ex3).getMessage() : ""));
}
}
protected int executeUpdate(String sql, Object... args) {
Connection con = null;
PreparedStatement pstmt = null;
int var5;
try {
con = this.getConn();
pstmt = this.getPs(con, sql, args);
var5 = pstmt.executeUpdate();
} catch (Exception var9) {
var9.printStackTrace();
throw new RuntimeException(var9);
} finally {
this.closeAll(con, pstmt, (ResultSet)null);
}
return var5;
}
public Object executeEntity(String sql, Object... args) {
List list = this.executeQuery(sql, args);
if (list.size() == 0) {
return null;
} else if (list.size() == 1) {
return list.get(0);
} else {
throw new RuntimeException("数据超过一条,请检查逻辑是否正确");
}
}
public List executeQuery(String sql, Object... args) {
List list = new ArrayList();
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = this.getConn();
pstmt = this.getPs(con, sql, args);
rs = pstmt.executeQuery();
while(rs.next()) {
Object o = this.rs2Obj(rs);
list.add(o);
}
ArrayList var13 = list;
return var13;
} catch (Exception var11) {
var11.printStackTrace();
throw new RuntimeException(var11);
} finally {
this.closeAll(con, pstmt, rs);
}
}
public Object executeSingle(String sql, Object... args) {
Object obj = 0;
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
Object var7;
try {
con = this.getConn();
pstmt = this.getPs(con, sql, args);
rs = pstmt.executeQuery();
if (rs.next()) {
obj = rs.getObject(1);
}
var7 = obj;
} catch (Exception var11) {
var11.printStackTrace();
throw new RuntimeException(var11);
} finally {
this.closeAll(con, pstmt, rs);
}
return var7;
}
public List executeObjects(String sql, Object... args) {
List list = new ArrayList();
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = this.getConn();
pstmt = this.getPs(con, sql, args);
rs = pstmt.executeQuery();
int columnCount = rs.getMetaData().getColumnCount();
while(rs.next()) {
Object[] objs = new Object[columnCount];
for(int n = 0; n < columnCount; ++n) {
objs[n] = rs.getObject(n + 1);
}
list.add(objs);
}
ArrayList var15 = list;
return var15;
} catch (Exception var13) {
var13.printStackTrace();
throw new RuntimeException(var13);
} finally {
this.closeAll(con, pstmt, rs);
}
}
private PreparedStatement getPs(Connection con, String sql, Object[] args) throws SQLException {
PreparedStatement pstmt = con.prepareStatement(sql);
for(int i = 1; i <= args.length; ++i) {
if (args[i - 1].getClass().getName().equals("java.util.Date")) {
pstmt.setTimestamp(i, new Timestamp(((java.util.Date)args[i - 1]).getTime()));
} else {
pstmt.setObject(i, args[i - 1]);
}
}
System.out.println("SQL:" + pstmt.toString());
return pstmt;
}
protected abstract Object rs2Obj(ResultSet var1) throws SQLException;
static {
Properties p = new Properties();
try {
p.load(getPropertiesInputStream());
ds = new DruidDataSource();
ds.setDriverClassName("com.mysql.cj.jdbc.Driver");
ds.setUrl("jdbc:mysql://" + p.getProperty("util.mysql.ip") + ":" + p.getProperty("util.mysql.port") + "/" + p.getProperty("util.mysql.db_name") + "?characterEncoding=utf-8&serverTimezone=UTC");
ds.setUsername(p.getProperty("util.mysql.username"));
ds.setPassword(p.getProperty("util.mysql.password"));
ds.setMaxActive(10);
ds.setMinIdle(1);
ds.setInitialSize(2);
ds.setMaxWait(10000L);
} catch (IOException var2) {
throw new RuntimeException("数据库配置文件读取失败", var2);
}
}
}