MyBatis Dynamic Curd

Source: Internet
Author: User

Xml

<select id= "selectbycondition" parametertype= "com.oracle.pojo.Student" resulttype= "Com.oracle.pojo.Student" >Select Id,name,address,gender,age from student where1=1 <iftest= "id! = NULL" >and ID=#{id}</if> <iftest= "Name! = NULL" >and name=#{name}</if> <iftest= "Address! = NULL" >and address like #{address}</if> <ifTest= "Gender! = NULL" >and gender=#{gender}</if> <ifTest= "Age! = 0" > and age=#{age}</if> </select> <sql id= "key" > <trim suffixoverrides= "," >ID,<iftest= "Name!=null" >name,</if> <iftest= "Address!=null" >address,</if> <ifTest= "Gender! = NULL" >Gender,</if> <ifTest= "Age! = 0" >Age ,</if> </trim> </sql> <sql id= "values" > <trim suffixoverrides= "," >#{id},<iftest= "Name!=null" >#{name},</if> <iftest= "Address!=null" >#{address},</if> <ifTest= "Gender! = NULL" >#{gender},</if> <ifTest= "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> <iftest= "Address!=null" >Address=#{address},</if> <iftest= "Age!=0" > Age=#{age},</if> </set>where ID=#{id}</update>

MyBatis Dynamic Curd

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.