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. 软工实践-Beta 冲刺 (7/7)

    队名:起床一起肝活队 组长博客:博客链接 作业博客:班级博客本次作业的链接 组员情况 组员1(队长):白晨曦 过去两天完成了哪些任务 描述: 1.界面的修改与完善 展示GitHub当日代码/文档签入记 ...

  2. Codeforces Round #157 (Div. 1) B. Little Elephant and Elections 数位dp+搜索

    题目链接: http://codeforces.com/problemset/problem/258/B B. Little Elephant and Elections time limit per ...

  3. mac下搭建MySql环境

    准备工作做完后,开始: 创建数据库 step1: 在mac中->系统偏好设置->最下边点MySQL 在弹出页面中 关闭mysql服务(点击stop mysql server) step2: ...

  4. charles抓取移动端app数据

    pc端为mac 移动端为android pc端 1.下载charles并安装 安利一个超好的良心网站(好多好用的软件都可以在上面找到,并且免费): http://xclient.info/search ...

  5. .NET 类库研究必备参考 添加微软企业库源码

    前不久,为大家提供了一个.NET 类库参考源码的网站,扣丁格鲁(谐音“coding guru”),使用了段时间,发现一些不方便的地方,特意做了一些更改,希望大家多提意见,下面是此次更改的地方. 更改1 ...

  6. area point sql

    UPDATE aa_info_area t,(SELECT areaId, areacenter,CONCAT('POINT(' ,substring_index(areacenter,',', 1) ...

  7. Json的JsonValueProcessor方法

    将对象转换成字符串,是非常常用的功能,尤其在WEB应用中,使用 JSON lib 能够便捷地完成这项工作. JSON lib能够将Java对象转成json格式的字符串,也可以将Java对象转换成xml ...

  8. Linux下的网卡Bonding

    1. 网卡Bonding一共有0-6七种mode,具体区别请自行搜索: 2. 建议通过nmtui命令在交互模式下配置,这样不会落下重要的字段,也不用去记忆到底有哪些字段: 3. 我的实验环境是VMWa ...

  9. 七类网线 支持10gb/s的速度的计算方法

    0. 说明 我是数学白痴, 只是套了下公式... 1. 七类网线的参数: 七类线 ISO/IEC 7类/F级标准 中最新的一种双绞线,它主要为了适应万兆位以太网技术的应用和发展.但它不再是一种非屏蔽双 ...

  10. centos7防火墙操作

    启动: systemctl start firewalld 关闭: systemctl stop firewalld 查看状态: systemctl status firewalld 开机禁用 : s ...