mybatis写mapper文件注意事项
< <
> >
& &
' '
" "
xml中的id(方法名)必须与Dao或mapper中的接口方法名一致
<!--添加-->
<!-- 创建订单操作 -->
<insert id="create" parameterType="dorder">
insert into e3datanew.d_order(
userId,
userName,
userAge,
userPhone,
userBrithDay,
userAddress
)
values(
#{userId,jdbcType=VARCHAR},
#{userName,jdbcType=VARCHAR},
#{userAge,jdbcType=DECIMAL},
#{userPhone,jdbcType=VARCHAR},
#{userBrithDay,jdbcType=DATE},
#{userAddress,jdbcType=VARCHAR}
)
</insert>
加上 jdbcType=VARCHAR 类型 空值时类型不会报错,
<!-- 修改-->
<update id="update" parameterType="map" flushCache="true" >
<![CDATA[
update e3datanew.d_order set
userName=#{userName,jdbcType=VARCHAR},
userAge=#{userAge,jdbcType=DECIMAL},
userPhone=#{userPhone,jdbcType=VARCHAR},
userBrithDay=#{userBrithDay,jdbcType=DATE},
userAddress=#{userAddress,jdbcType=VARCHAR}
where
userId=#{userId,jdbcType=VARCHAR}
]]>
</update>
<!--查询-->
<select id="findById" parameterType="String" resultType="dorder">
select
userId,
userName,
userAge,
userPhone,
userBrithDay,
userAddress
from e3datanew.d_order
where userId= #{userId,jdbcType=VARCHAR}
</select>
<!--查询-->
<select id="selectUsersCount" resultType="int">
<![CDATA[select count(*) from dorder ]]>
</select>
<!--删除-->
<delete id="delete" parameterType="String">
<![CDATA[ delete from dorder where userId = #{userId} ]]>
</delete>
<!--oracle分页 orderField排序字段 orderField排序方式-->
<select id="getListByLike" parameterType="map" resultType="dorder">
select * from(select t.*,rownum rn from ( select * from e3datanew.d_order
<where>
<if test="logictId!=null and logictId!='' ">
<![CDATA[ userId LIKE '%'||#{userId}||'%']]>
</if>
<if test="orderField!=null and orderField!='' ">
order by #{orderField,jdbcType=VARCHAR} #{orderDirection,jdbcType=VARCHAR}
</if>
</where>
) t where rownum < #{currentPage,jdbcType=DECIMAL}*#{numPerPage,jdbcType=DECIMAL}
) where rn > (#{currentPage,jdbcType=DECIMAL}-1)*#{numPerPage,jdbcType=DECIMAL}
</select>