Add, delete, change, check and other operations in the Mapper.xml file in the SSM framework

Source: Internet
Author: User

1<?xml version= "1.0" encoding= "UTF-8"?>2<! DOCTYPE Mapper Public "-//mybatis.org//dtd mapper 3.0//en" "Http://mybatis.org/dtd/mybatis-3-mapper.dtd" >3 4<!--================== Agent mode =================5Starting with the mapper tag, by/Mapper End, you can think of it as a space, a mapping file6 attribute namespace: The space name, which is used primarily in proxies. The namespace is the only one. 7The mapper tag and interface are linked together, namespace=Write interface path, map file to and interface in the same directory8-9<mapper namespace= "Com.dao.UserinfoDAO" >Ten<!--============= mapping relationship label ============= One Property Type: Write the package name Class name of the Po class, because the alias of the PO class was previously defined, this alias is written here A attribute ID: is the unique identifier for this mapping label - ID tags are unique identities in query result sets - Property Column: Queried column name the Attribute property: Is the column name specified in the PO class - is usually underlined after the original column name, which is fixed, this is the ID after _ -- -<resultmap type= "Com.po.UserinfoPO" id= "Userinfomap" > +<result column= "userid" property= "userid"/> -<result column= "LoginName" property= "LoginName"/> +<result column= "Loginpass" property= "Loginpass"/> A<result column= "username" property= "username"/> at<result column= "Upower" property= "Upower"/> -<result column= "Birthday" property= "Birthday"/> -<result column= "Sex" property= "sex"/> -</resultMap> -<!--================== Defining SQL Fragments ============== -SQL: is the SQL Fragment Label property ID is the unique identifier of the fragment-- in<sql id= "ZD" > - Userid,loginname,loginpass,username,upower,birthday,sex to</sql> +<!--Delete and change the ID in the label: Be sure to match the corresponding method name in the interface, - Resultmap The ID in the write map tag in the output type theParameterType: input type, canonical input data type, indicating the type of parameter used when querying *<!--Verify Login- $<select id= "Login" resultmap= "Userinfomap" parametertype= "Com.po.UserinfoPO" >Panax Notoginseng<!--introduce SQL fragments with an include tag, refID write id,where tags that define SQL fragments don't write in the fragment-- -Select <include refid= "Zd"/>From userinfo the<where> +Loginname=#{loginname} and Loginpass=#{loginpass} A</where> the</select> +      -<!--query user list-- $<select id= "userlist" resultmap= "Userinfomap" parametertype= "Com.po.UserinfoPO" > $<!--introduce SQL fragments with an include tag, refID write id,where tags that define SQL fragments don't write in the fragment-- -Select <include refid= "Zd"/>From userinfo -</select> the      -<!--query to modify the ID of the user information--Wuyi<select id= "UpdateID" resultmap= "Userinfomap" parametertype= "Com.po.UserinfoPO" > the<!--introduce SQL fragments with an include tag, refID write id,where tags that define SQL fragments don't write in the fragment-- -Select <include refid= "Zd"/>From userinfo Wu<where>userid=#{userid}</where> -</select> About      $<!--Modify user information-- -<update id= "Update" parametertype= "Com.po.UserinfoPO" > - Update UserInfo -Set Loginname=#{loginname},loginpass=#{loginpass},username=#{username}, Aupower=#{upower},birthday=#{birthday},sex=#{sex} +where userid=#{userid} the</update> -       $<!--Add user information-- the<insert id= "Insert" parametertype= "Com.po.UserinfoPO" > theInsert INTO UserInfo (<include refid= "Zd"/>)  the Values the (#{userid},#{loginname},#{loginpass},#{username},#{upower},#{birthday},#{sex}) -</insert> in          the<!--additions and deletions change the ID in the tag: Be sure to match the corresponding method name in the interface-- the<delete id= "Delete" parametertype= "int" > AboutDelete from UserInfo where userid=#{userid} the</delete> the      the<!--based on the user name fuzzy query, according to the permissions query-- +<select id= "Select" resultmap= "Userinfomap" parametertype= "Java.util.Map" > -<!--introduce SQL fragments with an include tag, refID write id,where tags that define SQL fragments don't write in the fragment-- theSelect <include refid= "Zd"/>From userinfoBayi<!--when the page does not enter a user name and select permissions, let its conditions always true, it becomes a full query-- the<where> the<iftest= "username = = null and username =" and upower = =-1 "> -and 1=1 -</if> the<ifTest= "Username! = null and Username! =" "> theand username like '%${username}% ' the</if> the<ifTest= "Upower! =-1" > -and upower=#{upower} the</if> the</where> the</select>94</mapper>

Follow-up-----

Add, delete, change, check, and so on in the Mapper.xml file in the SSM framework

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.