public class DbSource implements ISource{ private StringBuilder sqlBuilder=null; public DbSource(Record api) { String id=api.get("id")+""; String sqlstr=api.getStr("sqlstr"); sqlBuilder=new StringBuilder(); sqlBuilder.append("#sql(\"api_"+id+"\")"); sqlBuilder.append(" \n"); sqlBuilder.append(sqlstr); sqlBuilder.append(" \n"); sqlBuilder.append("#end"); System.out.println(sqlBuilder); } @Override public boolean isModified() { System.out.println("isModified"); return false; } @Override public String getKey() { System.out.println("getKey"); return null; } @Override public StringBuilder getContent() { System.out.println("getContent"); if(sqlBuilder==null){ throw new RuntimeException("Sql not found !"); } return sqlBuilder; } @Override public String getEncoding() { System.out.println("getEncoding"); return EngineConfig.DEFAULT_ENCODING; }
因为 我的api里面保存的只是一个sql语句,每次都需要addSqlTemplate,但是不知道为什么,只有第一次add 的sql 可以使用,后面再add就报错了,如下:
com.jfinal.plugin.activerecord.ActiveRecordException: java.sql.SQLException: sql is null at com.jfinal.plugin.activerecord.DbPro.find(DbPro.java:345) at com.jfinal.plugin.activerecord.DbPro.find(DbPro.java:356) at com.service.impl.IndexServiceImpl.getDataByApiAndParams(IndexServiceImpl.java:63) at com.controller.SqlController.getSelList(SqlController.java:41) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at com.jfinal.aop.Invocation.invoke(Invocation.java:73) at com.jfinal.core.ActionHandler.handle(ActionHandler.java:91) at com.jfinal.ext.handler.ContextPathHandler.handle(ContextPathHandler.java:48) at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:73) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at com.thetransactioncompany.cors.CORSFilter.doFilter(CORSFilter.java:209) at com.thetransactioncompany.cors.CORSFilter.doFilter(CORSFilter.java:244) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:442) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1082) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:623) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:722) Caused by: java.sql.SQLException: sql is null at com.alibaba.druid.pool.DruidPooledPreparedStatement$PreparedStatementKey.<init>(DruidPooledPreparedStatement.java:955) at com.alibaba.druid.pool.DruidPooledPreparedStatement$PreparedStatementKey.<init>(DruidPooledPreparedStatement.java:923) at com.alibaba.druid.pool.DruidPooledConnection.prepareStatement(DruidPooledConnection.java:336) at com.jfinal.plugin.activerecord.DbPro.find(DbPro.java:328) at com.jfinal.plugin.activerecord.DbPro.find(DbPro.java:343) ... 32 more
不能添加多个吗。求解