JFinal连接数据库,操作出现问题

@Override
public void configPlugin(Plugins plugins) {
    DruidPlugin db=new DruidPlugin("jdbc:mysql://localhost:3306/nosise_data","root","chejdj");
    plugins.add(db);
    ActiveRecordPlugin arp = new ActiveRecordPlugin(db);
    arp.addMapping("admin","admin_name", Admin.class);
    arp.addMapping("mobile_sensor","IMEI", MobileSensor.class);
    arp.addMapping("noise_data","IMEI", NoiseData.class);
}


public class Admin extends Model<Admin> {
    public static final Admin dao=new Admin().dao();

}

public class LoginController extends Controller{
    //web前端的登录信息
    //http://localhost:8080/noise_monitor/loginController/request_Login?admin_name=chejdj&admin_password=chejdj
        public  void request_Login(){
            System.out.println("调用了requestLogin方法");
            String admin_name=getPara("admin_name");
            System.out.println("admin_name的值为"+admin_name);
            String password=getPara("admin_password");
            System.out.println("password的值为"+password);
            //连接数据库失败
            if(Admin.dao==null){
                System.out.println("Admin.dao为空");
            }
   // new Admin() 操作的时候出现错误         
  new Admin().set("admin_name","hello").set("admin_password","123").save();

6PI5J7I%LHV%H[W3T`_2501.png

评论区

JFinal

2018-07-04 17:44

me.add(arp);这行代码添加一下

JFinal

2018-07-04 17:44

不添加也行,但是要添加下面这行:
arp.start();

foerst

2018-07-04 18:24

@JFinal 非常感谢,自己看文档没有看清楚,回复速度好快啊,我以为要等3,4天

热门反馈

扫码入社