SSM架構中的Mapper.xml檔案中的增、刪、改、查等操作

來源:互聯網
上載者:User

標籤:輸入   upd   null   doctype   包名   根據   efi   介面   ==   

 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 <!-- ==================代理方式================= 5 由mapper標籤開始,由/mapper結束,可以把它想成一個空間,是對應檔 6 屬性namespace:空間名,主要在代理中使用。這個namespace是唯一的。 7 這裡把mapper標籤和介面聯絡在一起了,namespace=寫介面路徑,對應檔要和介面在同一目錄下 8  --> 9 <mapper namespace="com.dao.UserinfoDAO">10     <!-- =============映射關係標籤=============11     屬性type:寫po類的包名類名,由於之前定義了po類的別名,這裡就寫這個別名12     屬性id:是這個映射標籤的唯一標識13     id標籤是查詢結果集中的唯一標識14     屬性column:查詢出來的列名15     屬性property:是po類裡所指定的列名16     通常會在原列名後面加底線,這是固定的,這裡就是id後面_17      -->18     <resultMap type="com.po.UserinfoPO" id="userinfoMap">19         <result column="userid" property="userid"/>20         <result column="loginname" property="loginname"/>21         <result column="loginpass" property="loginpass"/>22         <result column="username" property="username"/>23         <result column="upower" property="upower"/>24         <result column="birthday" property="birthday"/>25         <result column="sex" property="sex"/>26     </resultMap>27     <!-- ==================定義sql片段==============28     sql:是sql片段標籤屬性id是該片段的唯一標識 -->29     <sql id="zd">30         userid,loginname,loginpass,username,upower,birthday,sex31     </sql>32     <!-- 增刪改查標籤裡的id:一定要和介面裡對應的方法名一致,33          resultMap輸出類型裡寫映射標籤裡的id 34          parameterType:輸入類型,規範輸入資料類型,指明查詢時使用的參數類型-->35     <!-- 驗證登入 -->36     <select id="login" resultMap="userinfoMap" parameterType="com.po.UserinfoPO">    37         <!-- 用include標籤引入sql片段,refid寫定義sql片段的id,where標籤不要寫在片段裡 -->38         select <include refid="zd"/> from userinfo39         <where>            40                 loginname=#{loginname} and loginpass=#{loginpass}41         </where>42     </select>43     44     <!-- 查詢使用者列表 -->45     <select id="userList" resultMap="userinfoMap" parameterType="com.po.UserinfoPO">46         <!-- 用include標籤引入sql片段,refid寫定義sql片段的id,where標籤不要寫在片段裡 -->47         select <include refid="zd"/> from userinfo48     </select>49     50     <!-- 查詢修改使用者資訊的id -->51     <select id="updateid" resultMap="userinfoMap" parameterType="com.po.UserinfoPO">52         <!-- 用include標籤引入sql片段,refid寫定義sql片段的id,where標籤不要寫在片段裡 -->53         select <include refid="zd"/> from userinfo54         <where>userid=#{userid}</where>55     </select>56     57     <!-- 修改使用者資訊 -->58      <update id="update" parameterType="com.po.UserinfoPO">59          update userinfo 60          set loginname=#{loginname},loginpass=#{loginpass},username=#{username},61              upower=#{upower},birthday=#{birthday},sex=#{sex}62          where userid=#{userid}     63      </update>64      65     <!-- 添加使用者資訊 -->66     <insert id="insert" parameterType="com.po.UserinfoPO">67         insert into userinfo(<include refid="zd"/>) 68         values69         (#{userid},#{loginname},#{loginpass},#{username},#{upower},#{birthday},#{sex})70     </insert>71         72     <!-- 增刪改查標籤裡的id:一定要和介面裡對應的方法名一致 -->73     <delete id="delete" parameterType="int">74         delete from userinfo where userid=#{userid}75     </delete>76     77     <!-- 根據使用者名稱模糊查詢,根據許可權查詢 -->78     <select id="select" resultMap="userinfoMap" parameterType="java.util.Map">79         <!-- 用include標籤引入sql片段,refid寫定義sql片段的id,where標籤不要寫在片段裡 -->80         select <include refid="zd"/> from userinfo81         <!-- 當頁面沒有輸入使用者名稱和選擇許可權,就讓它的條件永遠為真,就變成全查詢了 -->82         <where>83             <if test="username == null and username = ‘‘ and upower == -1">84                 and 1=185             </if>86             <if test="username != null and username !=‘‘">87                 and username LIKE ‘%${username}%‘ 88             </if>        89             <if test="upower != -1">90                 and upower=#{upower} 91             </if>            92         </where>93     </select>94 </mapper>

後續-----

SSM架構中的Mapper.xml檔案中的增、刪、改、查等操作

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.