发布网友 发布时间:1天前
共2个回答
热心网友 时间:1分钟前
Returns:
true if the first result is a ResultSet object; false if the first result is an update count or there is no result
热心网友 时间:7分钟前
一、
insert,返回值是:新插入行的主键(primary key);需要包含<selectKey>语句,才会返回主键,否则返回值为null。
update/delete,返回值是:更新或删除的行数;无需指明resultClass;但如果有约束异常而删除失败,只能去捕捉异常。
queryForObject,返回的是:一个实例对象或null;需要包含<select>语句,并且指明resultMap;
queryForList,返回的是:实例对象的列表;需要包含<select>语句,并且指明resultMap。
二、
配置文件如下(desktop_common_sqlMap.xml):
[html] view plaincopy
<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>