public class _JFinalDemoGenerator { public static DataSource getDataSource() { String jdbcUrl="jdbc:sqlserver://127.0.0.1:1433;databaseName=Parking"; String user = "sa"; String password = "123112"; String driverClass = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; DruidPlugin druidPlugin = new DruidPlugin(jdbcUrl,user,password); druidPlugin.start(); return druidPlugin.getDataSource(); } public static void main(String[] args) { // base model 所使用的包名 String baseModelPackageName = "com.lastb7.dubbo.common.model.base"; // base model 文件保存路径 String baseModelOutputDir = PathKit.getWebRootPath() + "/src/main/java/com/lastb7/dubbo/common/model/base"; // model 所使用的包名 (MappingKit 默认使用的包名) String modelPackageName = "com.lastb7.dubbo.common.model"; // model 文件保存路径 (MappingKit 与 DataDictionary 文件默认保存路径) String modelOutputDir = baseModelOutputDir + "/.."; // 创建生成器 Generator generator = new Generator(getDataSource(), baseModelPackageName, baseModelOutputDir, modelPackageName, modelOutputDir); // 设置数据库方言 generator.setDialect(new SqlServerDialect()); // 设置是否生成链式 setter 方法 generator.setGenerateChainSetter(false); // 添加不需要生成的表名 generator.addExcludedTable("dt_article_goods_spec"); generator.addExcludedTable("dt_user_attach_log"); generator.addExcludedTable("PayModeDelete"); generator.addExcludedTable("PayModeUpdate"); generator.addExcludedTable("Sheet"); generator.addExcludedTable("adv"); // 设置是否在 Model 中生成 dao 对象 generator.setGenerateDaoInModel(true); // 设置是否生成链式 setter 方法 generator.setGenerateChainSetter(true); // 设置是否生成字典文件 generator.setGenerateDataDictionary(false); // 设置需要被移除的表名前缀用于生成modelName。例如表名 "osc_user",移除前缀 "osc_"后生成的model名为 "User"而非 OscUser generator.setRemovedTableNamePrefixes("t_"); // 生成 generator.generate(); // 生成ApiModelKit.java // ApiModelKit 所使用的包名 String apiModelKitPackageName = "com.lastb7.dubbo.common.model"; // 继承com.jfinal.plugin.activerecord.Table类 存放位置的包路径名 String extendsTablePackageName = "com.lastb7.dubbo.generator.Table"; // ApiModelKit 文件保存路径 (与MappingKit同目录) String apiModelKitOutputDir = PathKit.getWebRootPath() + "/src/main/java/com/lastb7/dubbo/common/model/"; // 生成 generatorApiModelKit(getDataSource(), apiModelKitPackageName, extendsTablePackageName, apiModelKitOutputDir); } } 连接SQLserver 报错: Build TableMeta ... Exception in thread "main" java.lang.RuntimeException: java.sql.SQLException: com.microsoft.sqlserver.jdbc.SQLServerDriver at com.jfinal.plugin.activerecord.generator.MetaBuilder.build(MetaBuilder.java:102) at com.jfinal.plugin.activerecord.generator.Generator.generate(Generator.java:217) at com.lastb7.dubbo.generator._JFinalDemoGenerator.main(_JFinalDemoGenerator.java:88) Caused by: java.sql.SQLException: com.microsoft.sqlserver.jdbc.SQLServerDriver at com.alibaba.druid.util.JdbcUtils.createDriver(JdbcUtils.java:510) at com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:563) at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:876) at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:872) at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:97) at com.jfinal.plugin.activerecord.generator.MetaBuilder.build(MetaBuilder.java:90) ... 2 more Caused by: java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:264) at com.alibaba.druid.util.JdbcUtils.createDriver(JdbcUtils.java:508) ... 7 more 2019-02-21 10:25:13 [ERROR]-[Thread: main]-[com.alibaba.druid.pool.DruidDataSource.init()]: dataSource init error java.sql.SQLException: com.microsoft.sqlserver.jdbc.SQLServerDriver at com.alibaba.druid.util.JdbcUtils.createDriver(JdbcUtils.java:510) at com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:563) at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:876) at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:872) at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:97) at com.jfinal.plugin.activerecord.generator.MetaBuilder.build(MetaBuilder.java:90) at com.jfinal.plugin.activerecord.generator.Generator.generate(Generator.java:217) at com.lastb7.dubbo.generator._JFinalDemoGenerator.main(_JFinalDemoGenerator.java:88) Caused by: java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:264) at com.alibaba.druid.util.JdbcUtils.createDriver(JdbcUtils.java:508) ... 7 more 不知道哪里错误,maven中也有SQLServer 的jar包,
项目:JFinal