用mybatis將SQL查詢語句”select * from user”的封裝為配置文件


用mybatis將SQL查詢語句”select * from user”的封裝為配置文件

定義一個xml映射文件,文件名見名知意。如user-mapper.xml,文件內容如下:

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE mapper

      PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"

      "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="suibian">

      <!-- 定義查詢語法的標簽.

           id - 語法命名, 由數字,字母,_ 組成. 數字不作為開頭字符.

           resultType - 定義結果類型. 代表一行數據對應一個什么java類型的對象.

       -->

      <select id="selectAllUsers" resultType="com.pojo.User">

           <!-- 標簽體中,定義要執行的SQL語句. -->

           select * from tb_user

      </select>

      <select id="selectUserById" resultType="com.pojo.User">

           select ID, Name, user_name as username, PassWORd, age from tb_user where id = 1

      </select>

      <select id="selectUsers" resultType="com.pojo.User">

           <![CDATA[

           select * from tb_user where id > 100

           ]]>

      </select>

</mapper>   


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM