jfinal有一个特别好的地方,sql查询的时候可以直接查record。但是要注意query和find的区别。

query返回的是List<object>,find返回的才是List<Record>

看源码

	/**
* @see #query(String, Object...)
* @param sql an SQL statement
*/
public <T> List<T> query(String sql) { // return List<object[]> or List<object>
return query(sql, NULL_PARA_ARRAY);
} /**
* @see #find(String, String, Object...)
* @param sql the sql statement
*/
public List<Record> find(String sql) {
return find(sql, NULL_PARA_ARRAY);
}

用法如下


/**
* 正确写法
*/
static void testDb0() {
String sql = "select wechat_openid from base_wechat_user ;";
List<String> data = Db.query(sql);
String r = data.get(0);
System.out.println(r.toString());
} /**
* 错误写法
*/
static void testDb1() {
String sql = "select wechat_openid from base_wechat_user ;";
List<Record> data = Db.query(sql);
Record r = data.get(0);
System.out.println(r.toString());
} /**
* 错误写法
*/
static void testDb2() {
String sql = "select id, wechat_openid from base_wechat_user ;";
List<Record> data = Db.query(sql);
Record r = data.get(0);
System.out.println(r.toString());
} /**
* 错误写法
*/
static void testDb3() {
String sql = "select * from base_wechat_user ;";
List<Record> data = Db.query(sql);
Record r = data.get(0);
System.out.println(r.toString());
} /**
* 正确写法
*/
static void testDb4() {
String sql = "select * from base_wechat_user ;";
List<Record> data = Db.find(sql);
Record r = data.get(0);
System.out.println(r.toString());
} /**
* 正确写法
*/
static void testDb5() {
String sql = "select wechat_openid from base_wechat_user ;";
List<Record> data = Db.find(sql);
Record r = data.get(0);
System.out.println(r.toString());
}

应用jfinal时要注意区分Db.query和Db.find的更多相关文章

  1. The 4th tip of DB Query Analyzer

    The 4th tip of DB QueryAnalyzer Ma Genfeng (Guangdong Unitoll Services incorporated, Guangzhou 51030 ...

  2. Data access between different DBMS and other txt/csv data source by DB Query Analyzer

        1 About DB Query Analyzer DB Query Analyzer is presented by Master Genfeng,Ma from Chinese Mainl ...

  3. Save results to different files when executing multi SQL statements in DB Query Analyzer 7.01

        1 About DB Query Analyzer DB Query Analyzer is presented by Master Genfeng,Ma from Chinese Mainl ...

  4. The new powerful SQL executing schedule monthly or weekly in DB Query Analyzer 7.01

    1 About DB Query Analyzer DB Query Analyzer is presented by Master Genfeng,Ma from Chinese Mainland. ...

  5. How to generate the complex data regularly to Ministry of Transport of P.R.C by DB Query Analyzer

    How to generate the complex data regularly to Ministry of Transport of P.R.C by DB Query Analyzer 1 ...

  6. How to create DB2 user function easily by DB Query Analyzer 6.03

    How to create DB2user function easily by DB Query Analyzer 6.03 Ma Genfeng (Guangdong Unitoll Servic ...

  7. Demonstration of DB Query Analyzer 6.03 Installation and Running on Microsoft Windows 8

    Demonstration of DB Query Analyzer 6.03 Installation and Running on Microsoft Windows 8 Ma Genfeng ( ...

  8. The 16th tip of DB Query Analyzer

                   The 16th tip of DB Query Analyzer      ---- SQL Schedule will be executed even DBMS h ...

  9. The 15th tip of DB Query Analyzer

    The 15th tip of DB Query Analyzer      ---- SQL Execute Schedule function is realized in 6.01 Ma Gen ...

随机推荐

  1. 我对git的认识

    Git 真的是不了解 也没听说过git 所以真的不知道从何谈起 所以就参考度娘啦! Git是一个开源的分布式版本控制系统,用以有效.高速的处理从很小到非常大的项目版本管理.Git 是 Linus To ...

  2. windows服务外壳工具

    Windows下将nginx安装为服务运行       今天看到nginx这个小服务器软件正式版更新到了1.4.2,想玩下它.这个服务器软件虽小,但功能强大,是开源软件,有着良好的性能,被很多个人.企 ...

  3. 每日站立会议——敏捷流程scrum实践

    每日站立会议是敏捷流程scrum中的很重要的一个制度之一. 功能:     1.快速同步进展,让项目组内部的员工互相了解彼此的进展,从而了解本项目的整体进展.      2.给每个人一种精神压力,信守 ...

  4. git add -A 和 git add . 的区别

    git add -A和 git add .   git add -u在功能上看似很相近,但还是存在一点差别 git add . :他会监控工作区的状态树,使用它会把工作时的所有变化提交到暂存区,包括文 ...

  5. SqlServer日期时间函数

    -- 判断是否当天,createdate为日期字段 -- ╔════════════════════╗ -- ============================================= ...

  6. python3 执行AES加密方法

    cmd执行命令:pip install pycryptodome # -*- coding: utf-8 -*- # __author__ = 'Carry' import base64 from C ...

  7. 第220天:Angular---路由

    内容介绍,为什么要使用前端路由? 在2005左右,兴起了一种叫做ajax的技术,有了ajax之后,我们向服务端提交数据的时候就不再需要使用from表单去提交了,因为from表单之间的提交会导致页面之间 ...

  8. Swagger实现API文档功能

    介绍: wagger也称为Open API,Swagger从API文档中手动完成工作,并提供一系列用于生成,可视化和维护API文档的解决方案.简单的说就是一款让你更好的书写API文档的框架. 我们为什 ...

  9. 使用refind引导多系统

    使用refind引导多系统 官网下载 rEFInd : http://www.rodsbooks.com/refind/getting.html 安装 rEFInd 教程: http://www.ro ...

  10. 滥用DNSAdmins权限进行Active Directory提权

      0x00 前言 除了在实现自己的DNS服务器功能之外,Microsoft还为该服务器实现自己的管理协议以便于管理与Active Directory域集成.默认情况下,域控制器也是DNS服务器; 大 ...