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. android 的helloworld没跑起来 原因

    <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com. ...

  2. XCODE的演变及使用经验分享

    IOS编程使用的是XCODE 编译器,安装XCODE你需要一台MAC(黑苹果也可以,个人不推荐,不稳定),然后直接去MAC上的APP STORE上下载安装就行,很简单,再次不做过多介绍... OK,那 ...

  3. asp.net如何隐藏表格(table)的一行

    直接用jquery $("#id1").click(function(){ $("#trId").css("display""no ...

  4. python字符串操作、文件操作,英文词频统计预处理

    1.字符串操作: 解析身份证号:生日.性别.出生地等. 凯撒密码编码与解码 网址观察与批量生成 解析身份证号:生日.性别.出生地等 def function3(): print('请输入身份证号') ...

  5. maven导入项目时出现“Cannot read lifecycle mapping metadata …… invalid END header (bad central directory offset)pom”错误的解决方法

    出现该错误是因为jar包版本不匹配,比如linux上的jar包导入到windows上了.可以将.m2\repository的org.apache.maven.plugins删掉然后让maven重新下载 ...

  6. sprintf函数 %6.2f

    %6.2f6表示数据表示至少6位,后面的.2表示小数点后保留两位 比如2342.123415用这个表示的话,结果就是2342.12如果不足六位就会在前面补空格超过六位的话正常显示 代码例子:int m ...

  7. 解决java使用Runtime.exec执行linux复杂命令不成功问题

    最近要实现一个Java调用一个复杂shell命令实现数据同步,该命令有管道重定向的语句,结果硬是执行不成功,而且也没异常报出.经过一段时间的折腾终于解决了此问题,权当做备忘记录下来(重点在红色框中的“ ...

  8. AJAX 跨域问题 php

    原生ajax请求方式: var xhr = new XMLHttpRequest(); xhr.open("POST", "http://xxxx.com/demo/b/ ...

  9. DAY8-Python学习笔记

    老样子课有点多,睡觉有点多,玩手机有点多,总结就是事情有点多.Python项目还没找好所以就没上手. 今天学习内容贴几张图...

  10. MT【153】缩小包围圈

    (清华2017.4.29标准学术能力测试3) 集合$S=\{1,2,\cdots,25\}$,$A\subseteq S$,且$A$ 的所有子集中元素之和不同.则下列选项正确的有(      ) A. ...