mybatis 动态curd
xml
<select id="selectByCondition" parameterType="com.oracle.pojo.Student" resultType="com.oracle.pojo.Student" > select id,name,address,gender,age from student where 1=1 <if test="id != null"> and id = #{id} </if> <if test="name != null"> and name = #{name} </if> <if test="address != null"> and address like #{address} </if> <if test="gender != null"> and gender = #{gender} </if> <if test="age != 0"> and age = #{age} </if> </select> <sql id="key"> <trim suffixOverrides=","> id, <if test="name !=null"> name, </if> <if test="address !=null"> address, </if> <if test="gender != null"> gender, </if> <if test="age != 0"> age, </if> </trim> </sql> <sql id="values"> <trim suffixOverrides=","> #{id}, <if test="name !=null"> #{name}, </if> <if test="address !=null"> #{address}, </if> <if test="gender != null"> #{gender}, </if> <if test="age != 0"> #{age}, </if> </trim> </sql> <insert id="dynainsert" parameterType="com.oracle.pojo.Student" > <selectKey keyColumn="id" keyProperty="id" resultType="java.lang.Long" order="BEFORE"> select student_seq.nextval as id from dual </selectKey> insert into student(<include refid="key"></include>) values (<include refid="values"></include>) </insert> <delete id="dynaDeleteArray" > delete student where id in <foreach collection="array" open="(" close=")" separator="," item="ids"> #{ids} </foreach> </delete> <delete id="dynaDeleteList"> delete from students where students_id in <foreach collection="list" open="(" close=")" separator="," item="ids"> #{ids} </foreach> </delete> <update id="dynaUpdate" parameterType="com.oracle.pojo.Student"> update student <set> <if test="address !=null"> address = #{address}, </if> <if test="age!=0"> age = #{age}, </if> </set> where id=#{id} </update>