Mybatis数据库操作的返回值
来源:互联网 发布:sql replace into用法 编辑:程序博客网 时间:2024/06/06 02:14
insert,返回值是:新插入行的主键(primary key);需要包含<selectKey>语句,才会返回主键,否则返回值为null。
update/delete,返回值是:更新或删除的行数;无需指明resultClass;但如果有约束异常而删除失败,只能去捕捉异常。
queryForObject,返回的是:一个实例对象或null;需要包含<select>语句,并且指明resultMap;
queryForList,返回的是:实例对象的列表;需要包含<select>语句,并且指明resultMap;
我的配置文件如下(desktop_common_sqlMap.xml):
- <typeAlias alias="UnlockTagInfo" type="com.desktop.common.bean.UnlockTagInfo" />
- <resultMap class="UnlockTagInfo" id="UnlockTagInfoResult">
- <result column="id" property="id" jdbcType="INTEGER" />
- <result column="name" property="name" jdbcType="VARCHAR" />
- <result column="description" property="description" jdbcType="VARCHAR" />
- <result column="priority" property="priority" jdbcType="INTEGER" />
- </resultMap>
- <insert id="insertUnlockTagInfo" parameterClass="map">
- <selectKey resultClass="int" keyProperty="id">
- 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>
- <update id="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>
- <delete id="deleteUnlockTagInfo" parameterClass="int">
- delete from
- desktop_unlock_tag
- where id=#value:INTEGER#
- </delete>
- <select id="countUnlockTagInfo" resultClass="int">
- select count(*)
- from
- desktop_unlock_tag
- </select>
- <sql id="selectUnlockTagInfo">
- select
- id,name,description,priority
- from
- desktop_unlock_tag
- </sql>
- <select id="findUnlockTagInfoById" parameterClass="int"
- resultMap="UnlockTagInfoResult">
- <include refid="selectUnlockTagInfo" />
- where id=#id:INTEGER#
- </select>
- <select id="listUnlockTagInfo" parameterClass="map"
- resultMap="UnlockTagInfoResult">
- <include refid="selectUnlockTagInfo" />
- order by
- modify_time desc limit #size:INTEGER#
- offset #start:INTEGER#
- </select>
0 0
- Mybatis/Ibatis,数据库操作的返回值
- Mybatis数据库操作的返回值
- Mybatis/Ibatis,数据库操作的返回值
- Mybatis/Ibatis,数据库操作的返回值
- Mybatis/Ibatis,数据库操作的返回值
- Mybatis/Ibatis,数据库操作的返回值
- Mybatis/Ibatis,数据库操作的返回值
- Mybatis/Ibatis,数据库操作的返回值
- Mybatis/Ibatis,数据库操作的返回值
- MyBatis 的数据库操作
- MyBatis使用MySQL数据库如何在执行insert操作后返回自增的主键
- Mybatis对有可能返回empty set的数据库查询结果进行操作
- MyBatis 获取insert操作返回的主键
- javase mybatis的操作数据库
- mybatis的oracle数据库操作
- Mybatis的简单数据库操作
- Mybatis操作数据库的方式
- Mybatis简单的操作数据库
- 表单全选切换
- js 上传图片预览
- R树的Java实现
- 【教程】天天在空调房中写代码,锻炼身体必不可少
- Android SimpleAdapter源码详解
- Mybatis数据库操作的返回值
- netty websocket
- 马云正式入主恒生电子
- Paxos领导者选举
- C语言数组与字符串小知识点
- EF CodeFist 多重外键约束
- 五大算法二:动态规划
- 下拉菜单显示隐藏切换
- Highcharts的选项配置参数