MyBatis从入门到精通:第一章实体类与Mapper.xml文件

博客提及Java的实体类和Mapper.xml文件,内容转载自https://www.cnblogs.com/junjie2019/p/10567008.html ,聚焦于Java后端开发相关内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

实体类:

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>

 

转载于:https://www.cnblogs.com/junjie2019/p/10567008.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值