应用jfinal时要注意区分Db.query和Db.find
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的更多相关文章
- The 4th tip of DB Query Analyzer
The 4th tip of DB QueryAnalyzer Ma Genfeng (Guangdong Unitoll Services incorporated, Guangzhou 51030 ...
- 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 ...
- 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 ...
- 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. ...
- 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 ...
- 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 ...
- 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 ( ...
- The 16th tip of DB Query Analyzer
The 16th tip of DB Query Analyzer ---- SQL Schedule will be executed even DBMS h ...
- 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 ...
随机推荐
- servlet几个常用的方法
servlet继承了HTTPServlet所以可以重写父类的方法,下面一 一介绍方法Dopost DoGet 比较常用不再介绍. 一.Init(),和Init(ServletConfig config ...
- Spring下使用开发webservice
依赖包 <!-- CXF Dependencies --> <dependency> <groupId>org.apache.cxf</groupId> ...
- js+Canvas 利用js 实现浏览器保存图片到本地
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- [转贴]infoQ VSTS被拆成5个部分,以Azure DevOps服务形式推出
VSTS被拆成5个部分,以Azure DevOps服务形式推出 http://www.infoq.com/cn/news/2018/09/vsts-divide5parts-azuredevops?u ...
- vue使用axios发送数据请求
本文章是基于vue-cli脚手架下开发 1.安装 npm install axios --s npm install vue-axios --s 2.使用.在index.js中(渲染App组件的那个j ...
- 关于sizeof
sizeof是求占用的内存空间的大小,并不是指数组长度.(strlen 的长度只适合char*类型) 例如. int a[10]={0}; 数组a的长度为sizeof(a)/sizeof(a[0])— ...
- 记录下log4j的两种配置方式
XML文件配置 <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE log4j:configura ...
- rpc 协议规范 之 rmi http webservice 和 一些框架
RPC(Remote Procedure Call)是远程调用,是一种思想,也是一种协议规范.简单地说就是能使应用像调用本地方法一样的调用远程的过程或服务,可以应用在分布式服务.分布式计算.远程服务调 ...
- springboot学习笔记-2 一些常用的配置以及整合mybatis
一.一些常用的配置 1.1 使用没有父POM的springboot 通过添加scope=import的依赖,仍然能获取到依赖管理的好处: <dependencyManagement> &l ...
- 【HLSDK系列】groupinfo的基本用法
如果你经常写AMXX,你应该会知道有个 pev->groupinfo 变量,但我猜大部分人都不会用这个变量,这个变量涉及很多实体处理功能,下面列举几个最常用的. ① 玩家与非玩家实体之间的碰撞检 ...