1. 程式人生 > >MyBatis從入門到精通:第一章實體類與Mapper.xml文件

MyBatis從入門到精通:第一章實體類與Mapper.xml文件

1.0 style 返回值 spa map 命名 定義 當前 入門到精通

實體類:

package tk.mybatis.simple.model;

public class Country {
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getCountryname() {
        return countryname;
    }

    public void setCountryname(String countryname) {
        
this.countryname = countryname; } public String getCountrycode() { return countrycode; } public void setCountrycode(String countrycode) { this.countrycode = countrycode; } private Long id; private String countryname; private String countrycode; }

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>XML的根文件,屬性namespace定義了當前XML的命名空間
-->
<mapper namespace="tk.mybatis.simple.mapper.CountryMapper"
> <!-- <select>元素,我們所定義的一個SELECT查詢 id屬性:定義了當前查詢的唯一一個id(這個id需要與實體類中的方法名對應麽?) resultType:定義了當前查詢的返回值類型, --> <select id="selectAll" resultType="Country"> SELECT id,countryname,countryCode FROM country </select> </mapper>

MyBatis從入門到精通:第一章實體類與Mapper.xml文件