1. 程式人生 > 其它 >Mybatis框架sql對映檔案.xml

Mybatis框架sql對映檔案.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!-- sql對映檔案(sql mapper) -->
<!--
1.指定約束檔案
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

2.
mybatis-3-mapper.dtd    是約束檔案的名稱,副檔名為dtd
作用:限制檢查在當前檔案中出現的標籤,屬性必須符合mybatis的要求

3.
<mapper namespace="org.mybatis.example.BlogMapper">
mapper   當前檔案的根標籤,必須的。
namespace   名稱空間,唯一值的,可以是自定義的字串
            要求你用dao介面的全限定名稱。
4.
在當前檔案中,可以使用特定的標籤,表示資料庫的特定操作
    <select>表示查詢
    <update>表示更新資料庫
    <inser>表示插入,放insert語句
    <delete>表示刪除,放delete語句
    
--> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.yuhang.dao.StudenDao"> <!-- select:查詢操作 id:你要執行的sql語法的唯一標識,mybatis會使用這個id的值來找到要執行的sql語句 可以自定義,但要求使用介面中的方法名 resultType:結果型別,遍歷sql語句執行後的結果集得到的java型別,
--> <select id="selectStudents" resultType="com.yuhang.domain.Student"> select id,name,email,age from student order by id </select> <!-- 資料庫的插入操作--> <insert id="insertStudent"> insert into student values(#{id},#{name},#{email},#{age}) </
insert> </mapper> <!-- sql對映檔案,mybatis會執行這些sql -->