Mybatis/Ibatis,資料庫操作的返回值
該問題,我百度了下,根本沒發現什麼有價值的文章;還是看原始碼(詳見最後附錄)中的註釋,最有效了!
insert,返回值是:新插入行的主鍵(primary key);需要包含<selectKey>語句,才會返回主鍵,否則返回值為null。
update/delete,返回值是:更新或刪除的行數;無需指明resultClass;但如果有約束異常而刪除失敗,只能去捕捉異常。
queryForObject,返回的是:一個例項物件或null;需要包含<select>語句,並且指明resultMap;
queryForList,返回的是:例項物件的列表;需要包含<select>語句,並且指明resultMap;
我的配置檔案如下(desktop_common_sqlMap.xml):
- <typeAliasalias="UnlockTagInfo"type="com.desktop.common.bean.UnlockTagInfo"/>
- <resultMapclass="UnlockTagInfo"id="UnlockTagInfoResult">
- <resultcolumn="id"property="id"jdbcType="INTEGER"/>
-
<resultcolumn="name"property="name"
- <resultcolumn="description"property="description"jdbcType="VARCHAR"/>
- <resultcolumn="priority"property="priority"jdbcType="INTEGER"/>
- </resultMap>
- <insertid="insertUnlockTagInfo"parameterClass="map">
-
<selectKeyresultClass="int"keyProperty
- select
- nextval('desktop_unlock_tag_id_seq') as id
- </selectKey>
- insert into
- desktop_unlock_tag(id,name,description,priority)
- values(#id:INTEGER#,#name:VARCHAR#,#description:VARCHAR#,#priority:INTEGER#)
- </insert>
- <updateid="updateUnlockTagInfo"parameterClass="map">
- update
- desktop_unlock_tag
- set modify_time=now(),priority=#priority:INTEGER#,
- name=#name:VARCHAR#,description=#description:VARCHAR#
- where
- id=#id:INTEGER#
- </update>
- <deleteid="deleteUnlockTagInfo"parameterClass="int">
- delete from
- desktop_unlock_tag
- where id=#value:INTEGER#
- </delete>
- <selectid="countUnlockTagInfo"resultClass="int">
- select count(*)
- from
- desktop_unlock_tag
- </select>
- <sqlid="selectUnlockTagInfo">
- select
- id,name,description,priority
- from
- desktop_unlock_tag
- </sql>
- <selectid="findUnlockTagInfoById"parameterClass="int"
- resultMap="UnlockTagInfoResult">
- <includerefid="selectUnlockTagInfo"/>
- where id=#id:INTEGER#
- </select>
- <selectid="listUnlockTagInfo"parameterClass="map"
- resultMap="UnlockTagInfoResult">
- <includerefid="selectUnlockTagInfo"/>
- order by
- modify_time desc limit #size:INTEGER#
- offset #start:INTEGER#
- </select>
- publicclass UnlockTagDaoImpl extends SqlMapClientDaoSupport implements
- UnlockTagDao {
- @Override
- public Integer addItem(String name, String desc, Integer priority) {
- SqlMapClientTemplate template = this.getSqlMapClientTemplate();
- Map<String, Object> args = new HashMap<String, Object>();
- args.put("name", name);
- args.put("description", desc);
- args.put("priority", priority);
- Object key = template.insert("DesktopCommon.insertUnlockTagInfo", args);
- return (Integer) key;
- }
- @Override
- publicboolean updateItem(Integer id, String name, String description,
- Integer priority) {
- SqlMapClientTemplate template = this.getSqlMapClientTemplate();
- Map<String, Object> args = new HashMap<String, Object>();
- args.put("id", id);
- args.put("name", name);
- args.put("description", description);
- args.put("priority", priority);
- try {
- int c = template.update("DesktopCommon.updateUnlockTagInfo", args);
-
相關推薦
Mybatis/Ibatis,資料庫操作的返回值
該問題,我百度了下,根本沒發現什麼有價值的文章;還是看原始碼(詳見最後附錄)中的註釋,最有效了! insert,返回值是:新插入行的主鍵(primary key);需要包含<selectKey>語句,才會返回主鍵,否則返回值為null。 updat
laravel資料庫操作返回值 Eloquent
新增 User::create([]); 成功返回Eloquent物件(包含id,created_at,updated_at和傳入值) 失敗丟擲異常 $user = new User(); $user->phone = '139......'; $us
ThinkPHP中資料庫操作返回值總結
文章轉自:http://www.baiwar.com/post/thinkphp-database-operations-in-the-return-value.html Thinkphp中的Think\Model類提供了資料庫的基本CURD(Create、Update
PYTHON自動化Day6-函式多個返回值和匿名函式、列表生成式,三元運算子,os模組,sys模組,時間模組,字典排序,資料庫操作,加密(md5)
一.函式多個返回值和匿名函式 #函式返回多個值,用一個變數接收 def say(): num1=1 num2=2 num3=3 return num1,num2,num3 res=say() print(res) #打印出來是元組。 函式如果返回多個值的話,會把返回的
Mybatis Update操作返回值
後端的資料持久化使用的是 Mybatis ,在做高併發下賬戶增減餘額的時候,打算使用樂觀鎖來解決這個問題。在獲取update操作的返回值時遇到了一個問題,似乎 Mybatis 進行 update 操作得到的 int 返回值並不是影響的行數。這下就尷尬了。 一般而言,我們
java中使用mybatis呼叫儲存過程,拿到返回值(單引數返回值)
service業務層呼叫dao層 注意:返回值直接從物件裡獲取 不需要拿物件接收再獲取 dao.uspGetUser(userPO);//物件封裝了儲存過程的入參和出參 count = userPO.getCount(); //count 是儲存過程的返回值 dao層介面 pu
Java 執行資料庫儲存過程,並帶返回值
前提是載入資源DataSource private JdbcTemplate jdbcTemplate; Java 呼叫儲存過程: @Override public String oneUniscInfoHisToDm(final Str
Finally-操作返回值
acc finall line style 返回值 console urn hide images Finally中操作返回值會出現一個問題?值沒有被改變? 1 static int M1() 2 { 3 int res
C#異步執行帶有返回值和參數的方法,且獲取返回值
urn 利用 回調方法 ext col list ont mes gate 很多時候需要用到這些小知識點,做做筆記一起成長 下面是需要異步執行的方法 //獲取所有的郵件 private List<EmailModel> GetEmailOnl
JDBC Update操作返回值和Insert操作返回主鍵
not null rest enc 不同 生成 statement -a AC ret JDBC Update操作返回值 在操作數據庫時,update操作會返回數據庫更新行數,但是在JDBC默認情況下則不會返回數據庫更新行數,這一點有所不同,在實際操作中可能會出現意想不到的
正則表達式中的match,test,exec,search的返回值
div gpo post arch 感覺 不知道 淺談 nbsp ear 今天突然被問到了正則表達式,因為長時間不用突然不知道怎麽用了,只知道有這麽個東西。然後去網上查了一下,感覺寫的不少,但解釋的有點模糊,今天我來淺談一下。 1,match的用法 A,在不加全局
使用 ResponseBodyAdvice 攔截Controller方法預設返回引數,統一處理返回值/響應體
使用 @ControllerAdvice & ResponseBodyAdvice 攔截Controller方法預設返回引數,統一處理返回值/響應體 1、Controller程式碼 以下是Controller查詢方法原始碼: /** * controller * * @au
ListView的getview不執行,並且getCount返回值大於0
這個問題網上描述了幾點原因,這裡只講我遇到的情況。 遇到的現象:Listview不顯示Item,手動點一下介面才會顯示。Log列印getCount返回值大於0。 我就說Listview及其Adapter寫個幾百個肯定是有的,應該不會有什麼問題的。然後百思不得解。 最後發現我的資料來自
Spring整合mybatis時,資料庫配置com.mysql.jdbc.Driver和com.mysql.cj.jdbc.Driver區別
1、#mysql-connector-java 5 用法 spring.datasource.driver-calss-name=com.mysql.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnico
為何Mybatis查詢無資料時返回值不是null
一、返回為一個List List<TeacherData> teacherData=null; teacherData=teacherService.queryTeacherByNameService(name);#假設資料庫沒有匹配的資料 if
java多執行緒 demo ,包含帶返回值的Callable和不帶返回值的Runnable
輸入int,利用callable取得double值,再用runnable列印 import java.util.concurrent.*; public class TestMultiThread { private static ExecutorService pool = nul
php精闢程式碼欣賞,資料庫操作類,封裝所有資料庫操作
下面是php各種程式碼庫,個人分享 <?php //******************************************************************* //此處構造一個數據庫操作類,封裝所有資料庫操作 //可以擴充套件便於後臺管理程
php 除錯微信介面時curl無返回值,file_get_contents有返回值的解決方法
在公司伺服器調式微信介面,使用curl獲取access_token完全沒有問題, 同樣的程式碼拿回家使用php內建webserver調試出現問題,curl沒有返回值,也沒報錯 原因是php內建webserver驗證了https的問題,把curl加入如下程式碼即可:
callable介面配合ExecutorService實現多執行緒處理資料,並接收返回值(2018-08-23)
/** * @author chenzhen * Created by chenzhen on 2018/8/22. */ @Data public class QuickPullGit implements Callable<ArrayList&l
採用HttpURLConnection方式呼叫第三方介面,介面的返回值經過unicode編碼處理
在介面的呼叫過程中,第三方介面的返回值使用unicode處理了,呼叫過程中一直報錯 改成下面這樣就可以了 public class TestStatic { public static void main(String[] args) throws Exception {