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. C++自学随笔(2)

    引用 就像人的别名,人不能只有别名,变量也不能只有引用. 指针类型的引用:*&指针引用名 = 指针. 如int a = 10;int *p =&a;int *&q =p1 co ...

  2. object-oriented first work

    前言:在星期三的第一次面向对象程序设计课,遇见我们的栋哥,初次见面,发现老师的幽默.....下课后,就给我们一道作业题目... 作业要求:Create a program that asks for ...

  3. MYSQL-不能创建表

    Can't create table '.\ticket\user_role.frm' (errno: 121) 语法是对的,但显示上面的错误 原因有三种 1.表名重复 2.以该名字命名的表之前创建过 ...

  4. java实现中值滤波均值滤波拉普拉斯滤波

    目录 来对下面的图像滤波,其实就是对各个像素点进行数学运算的过程 均值滤波 中值滤波 拉普拉斯滤波 Sobel滤波 注意 来对下面的图像滤波,其实就是对各个像素点进行数学运算的过程 均值滤波 均值滤波 ...

  5. python learning2.py

    L = ['Michael', 'Sarah', 'Tracy', 'Bob', 'Jack'] # 取前3个元素的笨方法 r = [] n = 3 for i in range(n): r.appe ...

  6. JDK和CGLIB动态代理原理

    1.JDK动态代理利用拦截器(拦截器必须实现InvocationHanlder)加上反射机制生成一个实现代理接口的匿名类, 在调用具体方法前调用InvokeHandler来处理. 2.CGLiB动态代 ...

  7. [转帖]NVMe到底是什么?用它的SSD有啥优势?

    NVMe到底是什么?用它的SSD有啥优势? 2015-8-20 14:00  |  作者:Strike   |  关键字:NVMe,SSD,PCI-E SSD,超能课堂 分享到       有关注SS ...

  8. Navicat for MySQL和Navicat Premium之间的区别

    首先两款软件都可以用来管理数据库链接MySQL和MariaDB 相对于新手或者前端工程师使用Navicat for MySQL就够了,功能相对于Navicat Premium比较少Navicat fo ...

  9. 相见恨晚的 scala - 01 [ 基础 ]

    简洁到不行,多一个分号都是不应该. 学习笔记: centOS 下安装 scala 和安装 jdk 一毛一样 . 1 . 不同于 Java 的变量声明 :( 但是和 js 很像 ) /** * Crea ...

  10. Delphi报的错误

    引入单元时提示Unit 'Unit1' already uses all the units in the project. 可能是没有添加环境变量造成的,需要手动输入代码引用单元. 和Environ ...