当前位置: 代码迷 >> 综合 >> Mybatis的xml文件中的Oracle语法
  详细解决方案

Mybatis的xml文件中的Oracle语法

热度:81   发布时间:2024-02-28 01:57:54.0

1. 批量插入,Mybatis参数是list

int insertList(@Param("studentList") List<Student> students);

<insert id="insertList" parameterType="java.util.List">insert into tb_student (s_id, s_name, s_age, create_date)<foreach collection="studentList" item="e" index="index" open="(" close=")" separator="union">select#{e.sId,jdbcType=VARCHAR},#{e.sName,jdbcType=VARCHAR},#{e.sAge,jdbcType=VARCHAR},#{e.createDate,jdbcType=TIMESTAMP}from dual</foreach>
</insert>

2. Mybatis参数是数组

List<Student> selectListByIds(@Param("ids") String[] ids);

<select id="selectListByIds" resultMap="BaseResultMap">select *from tb_studentwhere 1=1and s_id in (<foreach collection='ids' separator=',' item='id'>#{id,jdbcType=VARCHAR}</foreach>)
</select>

3. Mybatis中,Oracle的模糊查询

Student selectByName(@Param("sName") String sName);

<select id="selectByName" resultMap="BaseResultMap">select * from tb_studentwhere 1=1<if test="sName != null and sName != ''">and s_name like '%'||#{sName,jdbcType=VARCHAR}||'%'</if>
</select>

 

  相关解决方案