• jfinal配置rails的数据表


    鉴于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);
        }
    }
  • 相关阅读:
    币值转换
    抓老鼠啊!亏了还是赚了
    打印沙漏
    秋季学习总结
    记忆中最深刻的三位老师
    自我介绍
    docker 安装redis 和 mysql
    centos 安装docker
    celery的简单使用
    django redis配置和简单使用
  • 原文地址:https://www.cnblogs.com/ziyouchutuwenwu/p/5580128.html
Copyright © 2020-2023  润新知