码迷,mamicode.com
首页 > 其他好文 > 详细

jfinal配置rails的数据表

时间:2016-06-13 13:14:26      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:

鉴于rails的部署太可怕,所以有了使用rails的建表工具和migration,用jfinal来开发的想法,在此贴一下需要注意的地方

 

maven配置

<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.config

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

 

jfinal的model生成器

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.java

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);
    }
}

 

jfinal配置rails的数据表

标签:

原文地址:http://www.cnblogs.com/ziyouchutuwenwu/p/5580128.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!