MyBatis的传入参数parameterType类型分两种:
1. 1. 基本数据类型:int,string,long,Date
1. 2. 复杂数据类型:类和Map。
如何获取参数中的值:
2.1 基本数据类型:#{参数} 获取参数中的值;
2.2 复杂数据类型:#{属性名} ,map中则是#{key}。
基本数据类型案例:<sql id="Base_Column_List" >
id, car_dept_name, car_maker_name, icon,car_maker_py,hot_type
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" >
select
<include refid="Base_Column_List" />
from common_car_make
where id = #{id,jdbcType=BIGINT} 复杂数据类型案例:<select id="queryCarMakerList" 薯卜resultMap="BaseResultMap" parameterType="java.util.Map">
select
<include refid="Base_Column_List" />
from common_car_make cm
where 1=1
<if test="id != null">
and cm.id = #{id,jdbcType=DECIMAL}
</if>
<if test="carDeptName != null">
and cm.car_dept_name = #{carDeptName,jdbcType=VARCHAR}
</if>
<if test="carMakerName != null">
and cm.car_maker_name = #{carMakerName,jdbcType=VARCHAR}
</if>
<银手胡if test="hotType != null" >
and cm.hot_type = #{hotType,jdbcType=BIGINT}
</if>
ORDER BY cm.id
</select>锋拦
因为是字符串正早键型的数据,而加一 *** 作只适用于数值型的数。没有好的办法!考虑到效率问题,最好的办法是:在code创建索引,查询code的最大值(说白了举巧,就是排序),然后在程序中睁知加一 *** 作(注意数据类型转换!)
一般情况下是蚂袭需要的,否则mybatis强行插伏禅入可能会报错。简单的比如数闷厅兄据库中的字段是int类型,mybatis中用jdbcType=varchar类型去映射,这样不会报错。强制将字符串插入数据中整型。最好类型一致,避免不必要的异常错误出现。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)