jfinal配置rails的數據表

鑑於rails的部署太可怕,因此有了使用rails的建表工具和migration,用jfinal來開發的想法,在此貼一下須要注意的地方java

 

maven配置sql

<dependency>
      <groupId>com.jfinal</groupId>
      <artifactId>jfinal</artifactId>
      <version>2.2</version>
    </dependency>

    <!-- http://mvnrepository.com/artifact/com.mchange/c3p0 -->
    <dependency>
      <groupId>com.mchange</groupId>
      <artifactId>c3p0</artifactId>
      <version>0.9.5.2</version>
    </dependency>

    <!-- http://mvnrepository.com/artifact/org.postgresql/postgresql -->
    <dependency>
      <groupId>org.postgresql</groupId>
      <artifactId>postgresql</artifactId>
      <version>9.4.1208</version>
    </dependency>

 

resources下面的db.configapp

jdbcUrl = jdbc:postgresql://localhost:5432/my_rails_development
user = mmc
password = mmc

 

jfinal的model生成器maven

public static DataSource getDataSource() {
        Prop p = PropKit.use("db.config");
        C3p0Plugin c3p0Plugin = new C3p0Plugin(p.get("jdbcUrl"), p.get("user"), p.get("password"));
    //設置pgsql的DriverClass
        c3p0Plugin.setDriverClass("org.postgresql.Driver");
        c3p0Plugin.start();
        return c3p0Plugin.getDataSource();
    }

//設置pgsql的Dialect
gernerator.setDialect(new PostgreSqlDialect());  
gernerator.addExcludedTable("schema_migrations");

 

項目代碼裏面config工具

public void configPlugin(Plugins me) {

        Prop p = PropKit.use("db.config");
        C3p0Plugin cp = new C3p0Plugin(p.get("jdbcUrl"), p.get("user"), p.get("password"),"org.postgresql.Driver");
        cp.start();

        me.add(cp);

        ActiveRecordPlugin arp = new ActiveRecordPlugin(cp);
        arp.setDialect(new PostgreSqlDialect());
        _MappingKit.mapping(arp);
        me.add(arp);
    }

 

HelloController.javapost

public class HelloController extends Controller {

    public void index()
    {
        List<Users> users = Users.dao.find("select * from users;");
        String name = users.get(0).getName();
        renderText(name);
    }
}
相關文章
相關標籤/搜索