Mybatis笔记整理

Mybatis

官方文档
Spring、SpringMVC、SpringBoot

(1)持久层框架,它支持定制化 SQL、存储过程以及高级映射。

(2)避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集。

(3)可以使用简单的 XML 或注解来配置和映射原生信息,将接口和 Java 的 POJOs(Plain Ordinary Java Object,普通的 Java对象)映射成数据库中的记录。

1、持久层

MyBatis 是一款优秀的持久层框架,它支持自定义 SQL、存储过程以及高级映射。

MyBatis 免除了几乎所有的 JDBC 代码以及设置参数和获取结果集的工作。

MyBatis 可以通过简单的 XML 或注解来配置和映射原始类型、接口和 Java POJO(Plain Old Java Objects,普通老式 Java 对象)为数据库中的记录。

Dao层、Service层、Controller层

完成持久化工作的代码款、层界限十分明显

2、搭建环境

(1)搭建数据库

CREATE DATABASE `mybatis`;
USE `mybatis`;
CREATE TABLE `user`(
	`id` INT(20) NOT NULL,
	`name` VARCHAR(30) DEFAULT NULL,
	`pwd` VARCHAR(30) DEFAULT NULL,
	PRIMARY KEY(`id`)
)ENGINE = INNODB DEFAULT CHARACTER SET = utf8;

INSERT INTO `user`(`id`,`name`,`pwd`) 
VALUES(1,'xiaoming','121212'),(2,'xiaoli','131313'),(3,'xiaohuang','151515')

(2)新建项目(project)

  • 新建一个普通的maven项目

  • 删除src目录

  • 导入maven依赖

<!--pom.xml-->
<!--导入依赖-->
<dependencies>
        <!--mysql驱动-->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.47</version>
    </dependency>
        <!--mybatis-->
    <dependency>
        <groupId>org.mybatis</groupId>
        <artifactId>mybatis</artifactId>
        <version>3.5.2</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
    </dependency>
        
 <!--在build中配置resources。来防止我们资源导出失败的问题-->
    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                    <include>**/*.yml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                    <include>**/*.yml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
        </resources>
    </build>
        
 </dependencies>

导入依赖后在右边的Maven中会出现所导入的依赖:

依赖

2.1、创建模块(module)

<!--mybatis核心配置文件:mybatis-config.xml-->
<!--重点为mapper,注意全路径与斜杠/,第一行的UTF8没有杠“-”-->

<?xml version="1.0" encoding="UTF8" ?>
<!DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">

<configuration>
    <environments default="development">
        <environment id="development">
            <transactionManager type="JDBC"/>
            <dataSource type="POOLED">
                <property name="driver" value="com.mysql.jdbc.Driver"/>
                <property name="url" value="jdbc:mysql://localhost:3306/mybatis?useSSL=false&amp;useUnicode=true&amp;characterEncoding=UTF-8"/>
                <property name="username" value="root"/>
                <property name="password" value="zzh.2017"/>
            </dataSource>
        </environment>
    </environments>
    
      <!--每一个Mapper.xml都需要在Mybatis核心配置文件中注册-->
    <mappers>
        <mapper resource="com/kuang/dao/UserMapper.xml"/>
    </mappers>

</configuration>

在这里插入图片描述

String resource = "org/mybatis/example/mybatis-config.xml";
InputStream inputStream = Resources.getResourceAsStream(resource);
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

SqlSession 提供了在数据库执行 SQL 命令所需的所有方法,可以通过 SqlSession 实例来直接执行已映射的 SQL 语句。

  • 编写mybatis工具类
//MybatisUtils
package com.kuang.utils;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import java.io.InputStream;

//sqlSessionFactory获取sqlsession
public class MybatisUtils {

    public static SqlSessionFactory sqlSessionFactory;

    static {
        try {
            //使用mybati第一步:获取sqlSessionFactory对象,必做的三步
            String resource = "mybatis-config.xml";
            InputStream inputStream = Resources.getResourceAsStream(resource);
            sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        }catch(Exception e){
            e.printStackTrace();
        }
    }

    //有了 SqlSessionFactory,可以从中获得 SqlSession 的实例。
    // SqlSession 提供了在数据库执行 SQL 命令所需的所有方法,可以通过 SqlSession 实例来直接执行已映射的 SQL 语句
    public static SqlSession getSqlSession(){
        SqlSession sqlSession = sqlSessionFactory.openSession();
        return sqlSession;
   }
}

2.2、编写代码

  • 实体类

(包含相应数据库的列表名、空参、全参、setter、getter、toString)

package com.kuang.pojo;

//实体类
public class User {
    private int id;
    private String name;
    private String pwd;

    public User() {
    }

    public User(int id, String name, String pwd) {
        this.id = id;
        this.name = name;
        this.pwd = pwd;
    }

    public int getId() {
        return id;
    }

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

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPwd() {
        return pwd;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", pwd='" + pwd + '\'' +
                '}';
    }
}
  • Dao接口
package com.kuang.dao;
import com.kuang.pojo.User;
import java.util.List;
public interface UserMapper {
    //查询全部用户
    List<User> getUserList();

    //根据ID返回用户
    User getUserById(int id);

    //insert一个用户
    int addUser(User user);

    //修改用户
    int updateUser(User user);

    //删除用户
    int deleteUser(int id);
}
  • 接口实现类(由原来的UserDaolmpl转变为一个Mapper配置文件)

namespace:绑定一个对应的Dao/Mapper接口,必须为包名+点,不能是斜杠“/”

id:对应的namespace中的方法名

resultType:sql语句执行的返回值,为实体类的全路径

parameterType:返回值的类型

namespace中的包名要和Mapper接口的包名一致。

<?xml version="1.0" encoding="UTF8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.kuang.dao.UserMapper">

    <select id="getUserList" resultType="com.kuang.pojo.User">
        select  * from  mybatis.user
    </select>

    <select id="getUserById" resultType="com.kuang.pojo.User" parameterType="int">
        select * from mybatis.user where id = #{id}
    </select>

<!--    对象中的属性可以直接取出来-->
    <insert id="addUser" >
        insert into mybatis.user(id,`name`,pwd)
        values (#{id},#{name},#{pwd});
    </insert>

    <update id="updateUser" >
        update mybatis.user set `name` = #{name},pwd = #{pwd} where id = #{id};
    </update>

    <delete id="deleteUser" parameterType="int">
        delete from mybatis.user where id = #{id};
    </delete>
    
</mapper>

2.3、测试

注意点:

org.apache.ibatis.binding.BindingException: Type interface com.kuang.dao.UserMapper is not known to the MapperRegistry.

  • MapperRegistry是什么?

答:核心配置文件中注册mappers,,需要添加到mybits的核心配置文件mybatis-config.xml中。

<mappers>
    <!--路径必须斜杠“/”结尾-->
        <mapper resource="com/kuang/dao/UserMapper.xml"/>
</mappers>
  • 需要注意的是在maven导入依赖时的父工程中导入。
<!--在build中配置resources。来防止我们资源导出失败的问题-->
<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
            </includes>
            <filtering>false</filtering>
        </resource>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
            </includes>
            <filtering>false</filtering>
        </resource>
    </resources>
</build>
  • junit测试
package com.kuang.dao;
import com.kuang.pojo.User;
import com.kuang.utils.MybatisUtils;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;
import java.util.List;
public class UserMapperTest {
    @Test
    public void test(){

        //获得SqlSession对象
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        //方式一:执行SQL
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        List<User> userList = mapper.getUserList();
        for (User user : userList) {
            System.out.println(user);
        }
        //关闭SqlSession
        sqlSession.close();
    }
    @Test
    public void getUserById(){
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        User user = mapper.getUserById(1);
        System.out.println(user);
        sqlSession.close();
    }
    @Test
    public void addUser(){
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        mapper.addUser(new User(4,"xiaozhang","1616161"));
        sqlSession.commit();
        sqlSession.close();
    }
    @Test
    public void updateUser(){
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        mapper.updateUser(new User(3,"xiaoxiao","99999999"));
        sqlSession.commit();
        sqlSession.close();
    }
    @Test
    public void deleteUser(){
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        mapper.deleteUser(4);
        sqlSession.commit();
        sqlSession.close();
    }
}

最后的Project项目列表:
在这里插入图片描述

顺序:(maven—>工具类—>核心配置文件—>实体类—>接口—>接口配置文件—>测试)
在这里插入图片描述

输出结果(查询结果):
在这里插入图片描述

3、CRUD

(1)编写接口里的方法名,com.kuang.dao.UserMapper

(2)编写对应的mapper中的sql语句,UserMapper.xml

(3)编写测试文件

其中增、删、改需要提交事务:sqlSession.commit();

<!--实现接口的配置文件中的增删改查部分-->

<select id="getUserById" resultType="com.kuang.pojo.User" parameterType="int">
        select * from mybatis.user where id = #{id}
</select>

	<!--对象中的属性可以直接取出来-->
    <insert id="addUser" >
        insert into mybatis.user(id,`name`,pwd)values (#{id},#{name},#{pwd});
    </insert>

    <update id="updateUser" >
        update mybatis.user set `name` = #{name},pwd = #{pwd} where id = #{id};
    </update>

    <delete id="deleteUser" parameterType="int">
        delete from mybatis.user where id = #{id};
    </delete>

3.1、自动提交事务

①在Mybatis的工具类MybatisUtils中将getSqlSession里的方法的sqlSessionFactory.openSession();中加入参数true:(推荐)

public static SqlSession getSqlSession(){
    SqlSession sqlSession = sqlSessionFactory.openSession(true);
    return sqlSession;

②在测试类的sqlSession.close()上面手动添加sqlSession.commit();

//增删改需要提交事务
sqlSession.commit();
sqlSession.close();

4、万能Map

  • 当实体类或者数据库的表、字段或者参数过多时,应该考虑使用Map

  • Map传递参数,直接在sql中取出key即可

parameterType = “map”

  • 对象传递参数,直接在sql中取出对象即可

parameterType = “Object”

  • 只有一个基本类型参数的情况下,可以直接在sql中取到

  • 多个参数用Map,或者注解

在接口中:

    //insert一个用户
    int addUser2(Map map);

在实现接口的配置中:

    <insert id="addUser2" parameterType="map">
        insert into mybatis.user(id,pwd) values (#{userid},#{password});
    </insert>

在测试类中:

    //使用Map
    @Test
    public void addUser2(){
        //获得SqlSession对象
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        Map<String,Object> map = new HashMap<String, Object>();
        map.put("userid",5);
        map.put("password","8888888");
        mapper.addUser2(map);
        sqlSession.commit();
        sqlSession.close();
    }

5、模糊查询

  • java代码执行的时候,传递通配符%
//在配置文件中的sql
select * from mybatis.user where name like #{value}

//在测试类中的写法
List<User> userList = mapper.getUserLike("%李%");
for (User user : userList) {
            System.out.println(user);
        }

或者:

  • 在sql拼接中使用通配符(存在sql注入)
<!--在实现接口的配置中的sql语句-->
select * from mybatis.user where name like "%"#{value}"%"

6、配置解析

properties(属性)
settings(设置)
typeAliases(类型别名)
typeHandlers(类型处理器)
objectFactory(对象工厂)
plugins(插件)
environments(环境配置)
environment(环境变量)
transactionManager(事务管理器)
dataSource(数据源)
databaseIdProvider(数据库厂商标识)
mappers(映射器)

6.1、属性(properties)

可以通过properties属性来实现引用配置文件

这些属性可以在外部进行配置,并可以进行动态替换,既可以在典型的 Java 属性文件中配置这些属性,也可以在 properties 元素的子元素中设置。

  • 编写一个配置文件db.properties
driver = com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/mybatis?useSSL=false&useUnicode=true&characterEncoding=UTF-8
username=root
password=zzh.2017
  • 在核心配置文件(mybatis-config.xml)中引入
<!--引入外部配置文件-->    
<properties resource="db.properties"/>
<!--环境配置,注意与第一部分区分,value部分只用传db.properties里的名字即可,不用写内容-->
    <environments default="development">
        <environment id="development">
            <transactionManager type="JDBC"/>
            <dataSource type="POOLED">
                <property name="driver" value="${driver}"/>
                <property name="url" value="${url}"/>
                <property name="username" value="${username}"/>
                <property name="password" value="${password}"/>
            </dataSource>
        </environment>
    </environments>
  • 也可以在其中增加一些属性(假设db.properties中没有username和password)

(如果两个文件中有同一个字段,优先使用外部配置文件的)

<!--引入外部配置文件-->   
<properties resource="db.properties">
    <property name = "username" value = "root"/>
    <property name = "pwd" value = "11111"/>
</properties>

6.2、设置(settings)

6.3、类型别名(typeAliases)

在核心配置文件mybatis-config.xml中:

  • 类型别名可为 Java 类型设置一个缩写名字。 它仅用于 XML 配置,意在降低冗余的全限定类名书写
<!--给实体类起别名-->
<typeAliases>
    <typeAlias type="com.kuang.pojo.User" alias="User"/>
</typeAliases>

<!--在实现接口的配置文件中的sql中,resultType由"com.kuang.pojo.User"简写成"User"-->
<select id="getUserList" resultType="User">
    select  * from  mybatis.user
</select>
  • 也可以指定一个包名,MyBatis 会在包名下面搜索需要的 Java Bean

扫描实体类的包,默认别名就是这个类的类名,首字母小写

<!--给实体类起别名-->
<typeAliases>
    <package name="com.kuang.pojo"/>
</typeAliases>

<!--在实现接口的配置文件中的sql中,resultType由"com.kuang.pojo.User"简写成"User"-->
<select id="getUserList" resultType="user">
    select  * from  mybatis.user
</select>

实体类较少的时候使用第一种,否则使用第二种

6.4、环境配置(environment)

尽管可以配置多个环境,但每个 SqlSessionFactory 实例只能选择一种环境

在核心配置文件mybatis-config.xml中:

<environments default="development">
  <environment id="development">
    <transactionManager type="JDBC">
      <property name="..." value="..."/>
    </transactionManager>
    <dataSource type="POOLED">
      <property name="driver" value="${driver}"/>
      <property name="url" value="${url}"/>
      <property name="username" value="${username}"/>
      <property name="password" value="${password}"/>
    </dataSource>
  </environment>
</environments>
  • 学会配置多套运行环境

  • Mybatis默认的事务管理器是JDBC,连接池:POOLED

6.5、映射器(mappers)

MapperRegistry:注册绑定我们的Mapper文件

在核心配置文件mybatis-config.xml中:

  • 方式一,通过xml配置文件
    <!--每一个Mapper.xml都需要在Mybatis核心配置文件中注册-->
    <!--路径必须斜杠“/”结尾-->
    <mappers>
        <mapper resource="com/kuang/dao/UserMapper.xml"/>
    </mappers>
  • 方式二,通过class文件绑定注册
    <mappers>
        <mapper class="com.kuang.dao.UserMapper"/>
    </mappers>
  • 方式三,使用扫描包进行注册
    <mappers>
        <package name ="com.kuang.dao"/>
    </mappers>

方式二、三需要注意的点:

(1)接口和他的Mapper配置文件必须同名

(2)接口和他的Mapper配置文件必须在同一个包下

7、生命周期和作用域

在这里插入图片描述

  • SqlSessionFactoryBuilder:一旦创建了SqlSessionFactory,就不需要它了,局部变量

  • SqlSessionFactory:可以理解为数据库连接池,一旦被创建就应该在应用的运行期间一直存在,最佳作用域为应用作用域,单例模式

  • SqlSession:连接到连接池的一个请求,需要关闭。最佳作用域是请求或方法作用域
    在这里插入图片描述

8、结果集映射(resultMap)

先前的实体类中字段分别为id、name、pwd

若将其改为id、name、password
在这里插入图片描述

测试依据id查询的测试文件结果:
在这里插入图片描述

原因:在sql语句中为

select * from mybatis.user where id = #{id}
<!--等价为-->
select id,name,pwd from mybatis.user where id = #{id}

解决方法:

①修改sql语句(不建议)

select id,name,pwd as password from mybatis.user where id = #{id}

②结果集映射

id name pwd

id name password

在实现接口的配置文件中:UserMapper.xml

<!--结果集映射-->
    <resultMap id="UserMap" type="User">
<!--column为数据库中的字段,property为实体类中的属性-->
<!--当column与property相等时,此行可忽略-->
        <result column="id" property="id"/>
        <result column="name" property="name"/>
        <result column="pwd" property="password"/>
    </resultMap>

    <select id="getUserById" resultMap="UserMap" >
        select * from mybatis.user where id = #{id}
    </select>

在这里插入图片描述

9、日志

9.1、日志工厂

在这里插入图片描述

SLF4J
LOG4J (掌握)
LOG4J2
JDK_LOGGING
COMMONS_LOGGING
STDOUT_LOGGING (掌握)
NO_LOGGING

  • 在Mybatis中具体使用哪一个日志实现,在setting中设定

STDOUT_LOGGING 标准日志输出

在mybatis核心配置文件mybatis-config.xml中,配置日志:

(注意logImpl的拼写以及value的值后面不能有空格!!!)

    <settings>
        <setting name="logImpl" value="STDOUT_LOGGING"/>
    </settings>

输出结果:
在这里插入图片描述

9.2、LOG4J

通过一个配置文件来灵活进行配置,不需要修改应用的代码

①导入log4j的包

<dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
</dependency>

②配置log4j的配置文件log4j.properties

log4j.rootLogger=DEBUG,console,file

#控制台输出的相关设置
log4j.appender.console = org.apache.log4j.ConsoleAppender
log4j.appender.console.Target = System.out
log4j.appender.console.Threshold=DEBUG
log4j.appender.console.layout = org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=[%c]-%m%n

#文件输出的相关设置
log4j.appender.file = org.apache.log4j.RollingFileAppender
log4j.appender.file.File=./log/kuang.log
log4j.appender.file.MaxFileSize=10mb
log4j.appender.file.Threshold=DEBUG
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=[%p][%d{yy-MM-dd}][%c]%m%n

#日志输出级别
log4j.logger.org.mybatis=DEBUG
log4j.logger.java.sql=DEBUG
log4j.logger.java.sql.Statement=DEBUG
log4j.logger.java.sql.ResultSet=DEBUG
log4j.logger.java.sql.PreparedStatement=DEBUG

③配置log4j为日志的实现

    <settings>
        <setting name="logImpl" value="LOG4J"/>
    </settings>

④运行结果
在这里插入图片描述

简单使用:

①在要使用Log4j的类中,导入包(及其容易导错,注意时apache的包才正确)

import org.apache.log4j.Logger;

②日志对象,参数为当前的class

static Logger logger = Logger.getLogger(UserMapper.class);

③日志级别

    @Test
    public void testLog4j(){
        logger.info("info:进入了testLog4j");
        logger.debug("debug:进入了testLog4j");
        logger.error("error:进入了testLog4j");
    }

运行成功后项目中会多出一个log文件夹

10、分页

10.1、通过limit实现

  • 分页的sql使用语法:
SELECT * FROM User limit startIndex,pageSize
  • 接口
//分页
List<User> getUserByLimit(Map<String,Integer> map);
  • 实现接口的配置文件

(注意是resultMap并不是resultType):

<!--分页-->
<select id="getUserByLimit" parameterType="map" resultMap="UserMap">
    select * from mybatis.user limit #{startIndex},#{pageSize}
</select>
  • 测试类
    @Test
    public void getUserByLimit(){

        SqlSession sqlSession = MybatisUtils.getSqlSession();
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        //创建一个map对象
        HashMap<String, Integer> map = new HashMap<String, Integer>();
        //向map里面添加key,value
        map.put("startIndex",0);
        map.put("pageSize",2);

        List<User> userList = mapper.getUserByLimit(map);
        for (User user : userList) {
            System.out.println(user);
        }
        sqlSession.close();
    }

⚪在log4j日志下的输出:
在这里插入图片描述

10.2、通过RowBounds实现(不常用)

  • 接口
    //分页2
    List<User> getUserByRowBounds();
  • 实现接口的配置文件
<!--分页2-->
    <select id="getUserByRowBounds" resultMap="UserMap">
         select * from mybatis.user
    </select>
  • 测试类
    @Test
    public void getUserByRowBounds(){
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        //RowBounds实现
        RowBounds rowBounds = new RowBounds(1, 2);
        //通过java代码层面实现分页
        List<User> userList = sqlSession.selectList("com.kuang.dao.UserMapper.getUserByRowBounds", null, rowBounds);
        for (User user : userList) {
            System.out.println(user);
        }
        sqlSession.close();
    }

11、注解

11.1、注解遍历

①注解在接口(UserMapper)上实现

    @Select("select * from user")
    List<User> getUsers();

②需要在核心配置文件(mybatis-config.xml)中绑定接口

<!--日志设定:默认-->
    <settings>
        <setting name="logImpl" value="STDOUT_LOGGING"/>
    </settings>

<!--绑定接口-->
    <mappers>
        <mapper class="com.kuang.dao.UserMapper"/>
    </mappers>

③测试(遍历)

    @Test
    public void test01(){
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        List<User> users = mapper.getUsers();
        for (User user : users) {
            System.out.println(user);
        }
        sqlSession.close();
    }

输出结果:(null)
在这里插入图片描述

  • 本质:反射机制实现

  • 底层:动态代理

11.2、注解的CRUD

可以在工具类创建的时候实现自动提交事务

public static SqlSession getSqlSession(){
    SqlSession sqlSession = sqlSessionFactory.openSession();
    return sqlSession;
}

编写接口,增加注解

//方法存在多个参数时,所有参数前面必须都加上@Param("id")注解
@Select("select * from user where id = #{id}")
User getUserByID(@Param("id") int id);

@Insert("insert into mybatis.user(id,name,pwd) values (#{id},#{name},#{password})")
int addUser(User user);

@Update("update user mybatis.set name=#{name},pwd=#{password},where id = #{id}")
int updateUser(User user);

@Delete("delete from mybatis.user where id = #{id}")
int deleteUser(@Param("id") int id);

测试类(必须江接口注册绑定到我们的核心配置文件中)

@Test
public void getUserByID(){
    SqlSession sqlSession = MybatisUtils.getSqlSession();
    UserMapper mapper = sqlSession.getMapper(UserMapper.class);
    User userByID = mapper.getUserByID(1);
    System.out.println(userByID);
    sqlSession.close();
}

@Test
public void addUser(){
    SqlSession sqlSession = MybatisUtils.getSqlSession();
    UserMapper mapper = sqlSession.getMapper(UserMapper.class);
    mapper.addUser(new User(9,"xiaolong","777777"));
    sqlSession.close();
}

@Test
public void updateUser(){
    SqlSession sqlSession = MybatisUtils.getSqlSession();
    UserMapper mapper = sqlSession.getMapper(UserMapper.class);
    mapper.updateUser(new User(9,"tototo","666666"));
    sqlSession.close();
}

@Test
public void deleteUser(){
    SqlSession sqlSession = MybatisUtils.getSqlSession();
    UserMapper mapper = sqlSession.getMapper(UserMapper.class);
    mapper.deleteUser(1);
    sqlSession.close();
}

11.3、关于@Param()注解

  • 基本类型的参数或者String类型,需要加上

  • 引用类型不需要加

  • 如果只有一个基本类型,可以忽略,但是建议加上

  • 在SQL中引用的是@Param()中设定的属性名

12、Lombok插件

使用步骤:

  • 在IDEA中插入插件lombok
    在这里插入图片描述

  • 在项目中导入lomkom的jar包

<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>1.18.10</version>
    <scope>provided</scope>
</dependency>
  • 在实体类加注解即可
    在这里插入图片描述

  • 常用的lombok注解

@Data:无参构造,get,set,toString,hashCode,equals

@AllArgsConstructor:全参

@NoArgsConstructor:无参

@ToString

@EqualsAndHashCode

13、多对一处理

  • 一个老师对应多个学生SQL
CREATE TABLE `teacher` (
  `id` INT(10) NOT NULL,
  `name` VARCHAR(30) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=INNODB DEFAULT CHARSET=utf8

INSERT INTO teacher(`id`, `name`) VALUES (1, '秦老师'); 

CREATE TABLE `student` (
  `id` INT(10) NOT NULL,
  `name` VARCHAR(30) DEFAULT NULL,
  `tid` INT(10) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fktid` (`tid`),
  CONSTRAINT `fktid` FOREIGN KEY (`tid`) REFERENCES `teacher` (`id`)
) ENGINE=INNODB DEFAULT CHARSET=utf8INSERT INTO `student` (`id`, `name`, `tid`) VALUES ('1', '小明', '1'); 
INSERT INTO `student` (`id`, `name`, `tid`) VALUES ('2', '小红', '1'); 
INSERT INTO `student` (`id`, `name`, `tid`) VALUES ('3', '小张', '1'); 
INSERT INTO `student` (`id`, `name`, `tid`) VALUES ('4', '小李', '1'); 
INSERT INTO `student` (`id`, `name`, `tid`) VALUES ('5', '小王', '1');

13.1、搭建测试环境

1.导入lombok

2.新建实体类Student,Teacher

//Student
package com.kuang.pojo;
import lombok.Data;
@Data
@NoArgsConstructor
public class Student {
    private int id;
    private String name;

    //学生需要关联一个老师
    private Teacher teacher;
}
//Teacher
package com.kuang.pojo;
import lombok.Data;
@Data
@NoArgsConstructor
public class Teacher {
    private int id;
    private String name;
}

3.建立Mapper接口

//StudentMapper
package com.kuang.dao;
public interface StudentMapper {
}
//TeacherMapper
package com.kuang.dao;
import com.kuang.pojo.Teacher;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
public interface TeacherMapper {

    @Select("select * from teacher where id = #{tid}")
    Teacher getTeacher(@Param("tid") int id);
}

4.建立Mapper.xml文件

<?xml version="1.0" encoding="UTF8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.kuang.dao.StudentMapper">
</mapper>

<?xml version="1.0" encoding="UTF8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.kuang.dao.TeacherMapper">
</mapper>

5.在核心配置文件(mybatis-config.xml)中绑定注册我们的Mapper接口或者文件

<mappers>
    <mapper class="com.kuang.dao.TeacherMapper"/>
    <mapper class="com.kuang.dao.StudentMapper"/>
</mappers>

6.测试查询

import com.kuang.dao.TeacherMapper;
import com.kuang.pojo.Teacher;
import com.kuang.utils.MybatisUtils;
import org.apache.ibatis.session.SqlSession;

public class Test {
    public static void main(String[] args) {
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        TeacherMapper mapper = sqlSession.getMapper(TeacherMapper.class);
        Teacher teacher = mapper.getTeacher(1);
        System.out.println(teacher);
        sqlSession.close();
    }
}

附:文件目录
在这里插入图片描述

13.2、按照查询嵌套处理(子查询)

在StudentMapper.xml中配置:

<!--
    方法一:
    1.查询所有学生的信息
    2.根据查询出来的学生的tid,寻找对应的老师
-->
    <select id="getStudent" resultMap="StudentTeacher">
        select * from student
    </select>

    <resultMap id="StudentTeacher" type="Student">
        <!--property为实体类的属性,column为数据库里的字段-->
        <result property="id" column="id"/>
        <result property="name" column="name"/>
        <!--对象:association    集合:collection-->
        <association property="teacher" column="tid" javaType="Student" select="getTeacher"/>
    </resultMap>

    <select id="getTeacher" resultType="Teacher">
         select * from teacher where id = #{id}
    </select>

在这里插入图片描述

测试:

    @Test
    public void testStudent(){
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
        List<Student> StudentList = mapper.getStudent();
        for (Student student : StudentList) {
            System.out.println(student);
        }
        sqlSession.close();
    }

13.3、按照结果嵌套处理(连表查询)(推荐)

    <select id="getStudent2" resultMap="StudentTeacher2">
        select s.id sid,s.name sname,t.name tname
        from student s,teacher t
        where s.tid = t.id
    </select>

    <resultMap id="StudentTeacher2" type="Student">
         <!--property为实体类的属性,column为数据库里的字段-->
        <result property="id" column="sid"/>
        <result property="name" column="sname"/>
         <!--对象:association    集合:collection-->
        <association property="teacher" javaType="Teacher">
            <result property="name" column="tname"/>
        </association>
    </resultMap>

14、一对多处理

14.1、搭建测试环境

1.导入lombok

2.新建实体类Student,Teacher

//Student
package com.kuang.pojo;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
public class Student {
    private int id;
    private String name;
    private int tid;
}

//Teacher
package com.kuang.pojo;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@NoArgsConstructor
public class Teacher {
    private int id;
    private String name;

    //一个老师拥有多个学生
    private List<Student> students;
}

3.建立Mapper接口

//StudentMapper
package com.kuang.dao;
import com.kuang.pojo.Student;
import java.util.List;
public interface StudentMapper {
}

//TeacherMapper
package com.kuang.dao;
import com.kuang.pojo.Teacher;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
public interface TeacherMapper {
    //获取老师
    List<Teacher> getTeacher();
}

4.建立Mapper.xml文件

<?xml version="1.0" encoding="UTF8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.kuang.dao.StudentMapper">
</mapper>

<?xml version="1.0" encoding="UTF8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.kuang.dao.TeacherMapper">
        <select id="getTeacher" resultType="Teacher">
        	select * from mybatis.teacher;
    	</select>
</mapper>

5.在核心配置文件(mybatis-config.xml)中绑定注册我们的Mapper接口或者文件

<mappers>
    <mapper class="com.kuang.dao.TeacherMapper"/>
    <mapper class="com.kuang.dao.StudentMapper"/>
</mappers>

6.测试查询

@Test
    public void test() {
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        for(Teacher teacher : sqlSession.getMapper(TeacherMapper.class).getTeacher())
        {
            System.out.println(teacher);
        }
        sqlSession.close();
    }

14.2、按照查询嵌套处理(子查询)

<select id="getTeacher" resultMap="TeacherStudent">
    select * from mybatis.teacher where id = #{tid}
</select>
<resultMap id="TeacherStudent" type="Teacher">
    <result property="id" column="id"/>
    <result property="name" column="name"/>
    <collection property="students" javaType="ArrayList" ofType="Student" select="getStudentByTeacherId" column="id"/>
</resultMap>

<select id="getStudentByTeacherId" resultType="Student">
    select * from mybatis.student where tid = #{tid}
</select>

测试:

@org.junit.Test
public void test() {
    SqlSession sqlSession = MybatisUtils.getSqlSession();
    TeacherMapper mapper = sqlSession.getMapper(TeacherMapper.class);
    Teacher teacher = mapper.getTeacher(1);
    System.out.println(teacher);
    sqlSession.close();
}

14.3、按照结果嵌套查询(连表查询)(推荐)

<!--按结果嵌套查询-->
<select id="getTeacher2" resultMap="TeacherStudent2">
    select s.id sid,s.name sname,t.name tname,t.id tid
    from student s,teacher t
    where s.tid = t.id and t.id = #{tid}
</select>

<resultMap id="TeacherStudent2" type="Teacher">
    <result property="id" column="tid"/>
    <result property="name" column="tname"/>
    <!--javaType 指定属性的类型
    集合中的泛型信息,使用ofType
    -->
    <collection property="students" ofType="Student">
        <result property="id" column="sid"/>
        <result property="name" column="sname"/>
        <result property="tid" column="tid"/>
    </collection>
</resultMap>

14.4、小结

1.关联:association【多对一】

2.集合:collection【一对多】

3.javaType & ofType

  • javaType用来指定实体类中的属性类型

  • ofType用来指定映射到List或者集合中的pojo类型,泛型中的约束类型

注意点:

  • 保证SQL的可读性,故推荐连表查询

  • 注意一对多和多对一中的属性名和字段的问题

  • 如果问题不好排查错误,可以使用日志,建议使用Log4j

15、多态SQL

根据不同的条件生成不同的SQL语句,本质还是SQL,只是可以在SQL层面,去执行一个逻辑代码

15.1、搭建环境

CREATE TABLE `blog`(
`id` VARCHAR(50) NOT NULL COMMENT '博客id',
`title` VARCHAR(100) NOT NULL COMMENT '博客标题',
`author` VARCHAR(30) NOT NULL COMMENT '博客作者',
`create_time` DATETIME NOT NULL COMMENT '创建时间',
`views` INT(30) NOT NULL COMMENT '浏览量'
)ENGINE=INNODB DEFAULT CHARSET=utf8

1.导包

2.编写配置文件db.properties,mybatis-config.xml

  • db.properties同上

  • mybatis-config.xml (修改mapper,开启驼峰命名规则映射)

<?xml version="1.0" encoding="UTF8" ?>
<!DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">

<configuration>
    <!--引入外部配置文件-->
    <properties resource="db.properties"/>


    <settings>
        <!--引入日志-->
        <setting name="logImpl" value="STDOUT_LOGGING"/>
        <!--开启驼峰命名规则映射-->
        <setting name="mapUnderscoreToCamelCase" value="true"/>
    </settings>

    <!--给实体类起别名-->
    <typeAliases>
        <package name="com.kuang.pojo"/>
    </typeAliases>

    <environments default="development">
        <environment id="development">
            <transactionManager type="JDBC"/>
            <dataSource type="POOLED">
                <property name="driver" value="${driver}"/>
                <property name="url" value="${url}"/>
                <property name="username" value="${username}"/>
                <property name="password" value="${password}"/>
            </dataSource>
        </environment>
    </environments>

    <mappers>
        <mapper class="com.kuang.dao.BlogMapper"/>
    </mappers>

</configuration>

3.编写实体类pojo

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Blog {
    private String id;
    private String title;
    private String author;
    private Date createTime;    // 属性名和字段名不一致
    private int views;
}

4.编写BlogMapper接口

package com.kuang.dao;
import com.kuang.pojo.Blog;
public interface BlogMapper {
    //插入数据
    int addBlog(Blog blog);
}

5.实现接口的配置文件(注意namespace,id要和接口的方法名一致)

<?xml version="1.0" encoding="UTF8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.kuang.dao.BlogMapper">
    <insert id="addBlog" parameterType="blog">
        insert into mybatis.blog(id,title,author,create_time,views)
        values (#{id},#{title},#{author},#{createTime},#{views});

    </insert>

</mapper>

6.工具类(由于涉及增删改,打开自动提交事务)

package com.kuang.utils;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import java.io.InputStream;
//sqlSessionFactory获取sqlsession
public class MybatisUtils {
    public static SqlSessionFactory sqlSessionFactory;

    static {
        try {
            //使用mybati第一步:获取sqlSessionFactory对象,必做的三步
            String resource = "mybatis-config.xml";
            InputStream inputStream = Resources.getResourceAsStream(resource);
            sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        }catch(Exception e){
            e.printStackTrace();
        }
    }

    //有了 SqlSessionFactory,可以从中获得 SqlSession 的实例。
    // SqlSession 提供了在数据库执行 SQL 命令所需的所有方法,可以通过 SqlSession 实例来直接执行已映射的 SQL 语句
    public static SqlSession getSqlSession(){
        SqlSession sqlSession = sqlSessionFactory.openSession(true);
        return sqlSession;
    }
}

import java.util.UUID;
//获得随机ID
public class IDUtils {
    public static String getId(){
        return UUID.randomUUID().toString().replace(".","-");
    }
}

7.测试

    @org.junit.Test
    public void addBlogTest(){
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        BlogMapper mapper = sqlSession.getMapper(BlogMapper.class);
        Blog blog = new Blog();
        blog.setId(IDUtils.getId());
        blog.setTitle("Mybatis");
        blog.setAuthor("狂神说");
        blog.setCreateTime(new Date());
        blog.setViews(9999);
        mapper.addBlog(blog);

        blog.setId(IDUtils.getId());
        blog.setTitle("Java");
        mapper.addBlog(blog);

        blog.setId(IDUtils.getId());
        blog.setTitle("Spring");
        mapper.addBlog(blog);

        blog.setId(IDUtils.getId());
        blog.setTitle("微商");
        mapper.addBlog(blog);
        sqlSession.close();
    }
}

15.2、if

1.接口方法

    //查询博客
    List<Blog> queryBlogIF(Map map);

2.配置sql

  • (如果什么都没有输入则查询全部,输入title就查询title,输入author就查询author)
    在这里插入图片描述
<select id="queryBlogIF" parameterType="map" resultType="blog">
    select * from mybatis.blog
    <where>
        <if test="title != null">
            title = #{title}
        </if>
        <if test="author != null">
            and author = #{author}
        </if>
    </where>
</select>

3.测试

@Test
public void test02(){
    SqlSession sqlSession = MybatisUtils.getSqlSession();
    BlogMapper mapper = sqlSession.getMapper(BlogMapper.class);
    HashMap map = new HashMap();
   //map.put("title","Mybatis");
  //map.put("author","狂神说");
    List<Blog> blogs = mapper.queryBlogIF(map);
    for (Blog blog : blogs) {
        System.out.println(blog);
    }
    sqlSession.close();
}

15.3、choose(when,otherwise)

1.接口方法

List<Blog> queryBlogChoose(Map map);

2.配置文件

<select id="queryBlogChoose" parameterType="map" resultType="blog">
    select * from mybatis.blog
    <where>
        <choose>
            <when test="title != null">
                title = #{title}
            </when>
            <when test="author != null">
                and author = #{author}
            </when>
            <otherwise>
                and views = #{views}
            </otherwise>
        </choose>
    </where>
</select>

3.测试

@Test
  public void test03(){
      SqlSession sqlSession = MybatisUtils.getSqlSession();
      BlogMapper mapper = sqlSession.getMapper(BlogMapper.class);
      HashMap map = new HashMap();
      //map.put("title","Mybatis");
      //map.put("author","狂神说");
      map.put("views",1000);
      List<Blog> blogs = mapper.queryBlogChoose(map);
      for (Blog blog : blogs) {
          System.out.println(blog);
      }
      sqlSession.close();
  }

15.4、trim(where,set)

在这里插入图片描述

1.接口方法

//更新博客
int updateBlog(Map map);

2.配置文件

<update id="updateBlog" parameterType="map">
    update mybatis.blog
    <set>
        <if test="title != null">
            title = #{title},
        </if>
        <if test="author != null">
            author = #{author}
        </if>
    </set>
    where id = #{id}
</update>

3.测试

@Test
public void test04(){
    SqlSession sqlSession = MybatisUtils.getSqlSession();
    BlogMapper mapper = sqlSession.getMapper(BlogMapper.class);
    HashMap map = new HashMap();
    map.put("title","Mybatis009");
    //map.put("author","狂神说");
    map.put("id","cd517770-2ada-4960-bb28-00ffbf375f0e");
    mapper.updateBlog(map);
    sqlSession.close();
}

15.5、foreach(遍历)

在这里插入图片描述

1.接口

//查询第1-2-3号记录的博客
List<Blog> queryBlogForeach(Map map);

2.配置文件

<!--select * from mybatis.blog where 1=1 and (id=1 or id=2 or id=3)-->
<select id="queryBlogForeach" parameterType="map" resultType="blog">
    select * from mybatis.blog
    <where>
        <!--以“and (”开头,以“)”结尾,以“or”为分隔符,注意and后面有空格-->
        <!--collection为集合,item为集合里的项-->
        <foreach collection="ids" item="id" open="and (" close=")" separator="or">
            id = #{id}
        </foreach>
    </where>
</select>

3.测试

@Test
public void test05(){
    SqlSession sqlSession = MybatisUtils.getSqlSession();
    BlogMapper mapper = sqlSession.getMapper(BlogMapper.class);
    HashMap map = new HashMap();
    ArrayList<Integer> ids = new ArrayList<Integer>();
    ids.add(1);
    map.put("ids",ids);
    List<Blog> blogs = mapper.queryBlogForeach(map);
    for (Blog blog : blogs) {
        System.out.println(blog);
    }
    sqlSession.close();
}

在这里插入图片描述

15.6、SQL片段

可以将一些功能的部分抽取出来,方便复用

将15.2的if判断语句抽取出来

<!--使用SQL标签抽取公共的部分-->
<sql id="if-title-author">
    <if test="title != null">
        title = #{title}
    </if>
    <if test="author != null">
        and author = #{author}
    </if>
</sql>
<!--在需要使用的方法使用include标签引用即可-->
<select id="queryBlogIF" parameterType="map" resultType="blog">
    select * from mybatis.blog
    <where>
       <include refid="if-title-author"></include>
    </where>

</select>

注意事项:

  • 最好基于单表来定义SQL片段

  • 不要存在where标签

15.7、小结

多态SQL就是在拼接SQL语句,我们只要保证SQL的正确性,按照SQL的格式去排列组合就可以了

建议:

⚪先在Mysql中写出完整的SQL,再对应的去修改成为我们的多态SQL实现通用即可。

16、缓存

16.1、一级缓存(sqlSession级别)

  • 一级缓存默认开启,只在一次sqlSession中有效,也就是拿到连接到关闭连接这个时间段,就相当于一个Map

缓存失效的情况:

1.查询不同的东西

2.增删改操作,可能会该表原来的数据,所以必定会刷新缓存

3.查询不同的Mapper.xml

4.手动清理缓存:sqlSession.clearCach()

16.2、二级缓存(cache)

在这里插入图片描述

步骤

1.开启全局缓存(在mybatis-config.xml中)

<setting name="cacheEnabled" value="true"/>

2.在当前Mapper.xml中使用二级缓存

<cache/>

小结:

  • 只要开启了二级缓存,在同一个Mapper下就有效

  • 所有的数据都会先放在一级缓存中

  • 只有当会话提交或者关闭的时候,才会提交到二级缓存中
    在这里插入图片描述

16.3、自定义缓存(ehcache)

  • Ehcache是一种广泛使用的开源Java分布式缓存,主要面向通用缓存

1.导包

<!-- https://mvnrepository.com/artifact/org.mybatis.caches/mybatis-ehcache -->
<dependency>
    <groupId>org.mybatis.caches</groupId>
    <artifactId>mybatis-ehcache</artifactId>
    <version>1.1.0</version>
</dependency>

2.添加配置文件ehcache.xml

<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"
         updateCheck="false">

    <diskStore path="./tmpdir/Tmp_EhCache"/>

    <defaultCache
            eternal="false"
            maxElementsInMemory="10000"
            overflowToDisk="false"
            diskPersistent="false"
            timeToIdleSeconds="1800"
            timeToLiveSeconds="259200"
            memoryStoreEvictionPolicy="LRU"/>

    <cache
            name="cloud_user"
            eternal="false"
            maxElementsInMemory="5000"
            overflowToDisk="false"
            diskPersistent="false"
            timeToIdleSeconds="1800"
            timeToLiveSeconds="1800"
            memoryStoreEvictionPolicy="LRU"/>
</ehcache>

3.在Mapper.xml中引入ehcache

<!--自定义缓存-->
<cache type="org.mybatis.caches.ehcache.EhcacheCache"/>

以后会使用Redis数据库来做缓存

注:本笔记来自自学B站UP主遇见狂神说整理得来,十分良心,安利安利!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值