【已解决】错误信息 File not found in CLASSPATH or JAR : "sql/user.sql"
具体配置
BaseJfinalConfig arp.setContainerFactory(new CaseInsensitiveContainerFactory()); arp.setShowSql(isShowSql); //arp.setBaseSqlTemplatePath(PathKit.getRootClassPath() + "/sql"); List<File> files = getFileList(PathKit.getRootClassPath() + "/sql"); // 通过JfinalConfig中继承方法实现表关联 this.addMappingKit(dbType, arp); public class ActiveRecordMapping implements ActiveRecordMappingKit { @Override public void mapping(String dbSource, ActiveRecordPlugin arp) { arp.getEngine().setToClassPathSourceFactory(); switch (dbSource) { case "ORA": arp.addMapping("T_USER", User.class); break; case "mysql": arp.addMapping("t_user", User.class); break; case "POST": break; case "MSSQL": arp.addMapping("t_user", User.class); arp.addSqlTemplate("/sql/user.sql"); break; case "Sqlite3": break; case "AnsiSql": break; default: arp.addMapping("USER_TEST", UserTest.class); break; } } } 解决方式: 修改pom.xml文件中,在resource中<include>**/*.sql</include> <resource> <directory>src/main/resources</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> <include>**/*.sql</include> </includes> <filtering>false</filtering> </resource> maven一下即可
项目:JFinal
arp.setBaseSqlTemplatePath(PathKit.getRootClassPath() + "/sql");
如果是老版本,要还添加下面的代码:
arp.getEngine().setSourceFactory(new ClassPathSourceFactory());
这个配置就可以从 class path 和 jar 中读取模板了
后续就可以通过 arp.addSqlTemplate("/sql/user.sql") 来添加模板了