鉴于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.</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().getName();
renderText(name);
}
}