Mybatis

本文介绍了Mybatis的环境搭建,包括Maven依赖、数据库驱动和Mybatis的配置。讲解了如何创建子模块,编写核心配置文件,以及如何绑定Dao/Mapper.xml到接口。接着详细描述了编写实体类、Dao接口、接口实现类以及测试过程。文章还讨论了可能出现的异常及其解决方案,并概述了Mybatis的执行流程。此外,还涵盖了Mybatis的配置解析,包括属性、环境配置、类型别名、设置、映射器等。最后,文章提到了日志配置、分页、动态SQL、缓存以及Lombok的使用等高级话题。

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

第一个mybatis程序
前提:了解maven依赖还有jdbc和mysql。
:搭建环境

  • 导入数据库驱动和mybatis和junit依赖

:创建子模块

  • 编写mybatis核心配置文件,在模块的resources文件夹下
<?xml version="1.0" encoding="UTF-8" ?>
<!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.cj.jdbc.Driver"/>
                <property name="url" value="jdbc:mysql://localhost:3306/mybatis?userSSL=true&amp;useUnicode=true&amp;characterEncoding=UTF-8"/>
                <property name="username" value="root"/>
                <property name="password" value="123456"/>
            </dataSource>
        </environment>
    </environments>
    <mappers>
        <mapper resource="com/qiufen/dao/UserMapper.xml"/>
    </mappers>
</configuration>

在核心配置文件中注册的Dao/Mapper.xml对应绑定到Dao/Mapper.xml中namespace绑定的接口,这个包名必须和接口的名要一致。域名使用’/'隔开!!!

  • 编写mybatis工具类:
package com.qiufen.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.IOException;
import java.io.InputStream;

//mybatis工具类,即获得sqlSessionFactory对象
public class MybatisUtils {
    private static SqlSessionFactory sqlSessionFactory;
    static {
        String resource = "mybatis-config.xml";
        InputStream inputStream = null;
        try {
            //使用mybatis第一步:获取sqlSessionFactory
            inputStream = Resources.getResourceAsStream(resource);
            sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    /*
     * 既然有了 SqlSessionFactory,顾名思义,我们可以从中获得 SqlSession 的实例。
     * SqlSession 提供了在数据库执行 SQL 命令所需的所有方法。你可以通过 SqlSession 实例来直接执行已映射的 SQL 语句。
     * */

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

三:编写代码

  • 实体类
package com.qiufen.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.qiufen.dao;

import com.qiufen.pojo.User;

import java.util.List;
//UserDao接口等价于mapper即UserMapper
public interface UserDao {
    List<User> getUserList();
}

  • 接口实现类
<?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="com.qiufen.dao.UserDao">
    <select id="getUserList" resultType="com.qiufen.pojo.User">
        select *
        from mybatis.user
    </select>
</mapper>

此xml配置文件被SqlSession的调用,与之前的jdbc操作相当于实现此接口。
id为实现接口中的方法名,即对应namespace中的方法名。
返回类型要写全域名。

  • 测试:
package com.qiufen.dao;

import com.qiufen.pojo.User;
import com.qiufen.utils.MybatisUtils;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import java.util.List;

public class UserDaoTest {
    @Test
    public void test(){
        //获得sqlSession对象
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        //sqlSession执行sql:通过getMapper方法(接口的class对象)获得UserDao对象,才能使用其中的方法
        //如何拿到要执行的sql,通过mapper或dao,因为面向接口编程,所以我们只需要拿到接口就可以了
        UserDao mapper = sqlSession.getMapper(UserDao.class);
        List<User> userList = mapper.getUserList();
        for (User user : userList) {
            System.out.println(user);
        }
        //一定要关闭sqlSession
        sqlSession.close();
    }
}

四:可能遇到的异常

  • 绑定异常:Type Interface xxx is not know to the MapperRegistry

  • 解决方法:在核心配置文件中注册每一个Dao/Mapper.xml

  • 或者是xxxmapper.xml中的实现的方法id与接口中的方法名不同!

  • 初始化异常
    由于maven的约定大于配置,可能我们写的配置文件,无法导出或生效的问题。

  • 解决方法:在build中配置resources,来防止我们资源导出失败的问题,为了防止失败也可以在子模块中加入。注意:刚加入后要记得reload all maven project!!!并且核心配置文件中不能有中文注释!!!

  • 每一个Mapper.xml都需要在mybatis核心配置文件中注册,如果配置了好几个xxxMapper.xml,但是只有一个与接口绑定(每一个xxx.xml通过namespace与接口绑定),测试的时候也会发生异常!!!

Mybatis执行流程
在这里插入图片描述

CRUD

  • insert
    参数类型为对象时,对象中的属性可以直接取出来。必须跟对象中的字段对应。
    sql语句中通过#{}来取值。
<insert id="addUser" parameterType="com.qiufen.pojo.User">
        insert into mybatis.user(id, name, pwd)
        values (#{id},#{name},#{pwd})
</insert>
<!--
id:对应与namespace绑定接口中的方法名
parameterType:参数类型
resultType:sql语句执行的返回值
-->

参数类型为int时可以忽略不写,返回数据类型为基本数据类型的别名详细如下:
在这里插入图片描述

public void test3() {
     SqlSession sqlSession = MybatisUtils.getSqlSession();
     UserDao mapper = sqlSession.getMapper(UserDao.class);
     int num = mapper.addUser(new User(4, "东芝", "999999"));
     if (num > 0) {
         System.out.println("插入成功~");
     }
     sqlSession.commit();
     sqlSession.close();
}

注意:增删改查需要提交事务!!!

  • delete
<delete id="deleteUser" parameterType="int">
        delete from mybatis.user
        where id = #{int}
</delete>
  • update
<update id="updateUser" parameterType="com.qiufen.pojo.User">
        update mybatis.user
        set name = #{name},
            pwd=#{pwd}
        where id = #{id}
</update>
public void test4(){
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        UserDao mapper = sqlSession.getMapper(UserDao.class);
        mapper.updateUser(new User(4, "东芝", "666666"));
        sqlSession.commit();
        sqlSession.close();
}
  • select
<select id="getUserById" parameterType="int" resultType="com.qiufen.pojo.User">
    select *
    from mybatis.user
    where id = #{id}
</select>
  • Map(key-value)
    当实体类中的属性或者参数过多时,可以考虑使用map。
    例如要修改一个用户的密码,如果参数类型是User,但是这个User有很属性,我们就必须去new一个User对象,并把它的所有字段补充上,假如使用map作为参数类型,则不用。
<insert id="addUser2" parameterType="map">
        insert into mybatis.user(id,name,pwd)
        values (#{userid},#{userName},#{userPwd})
</insert>
public void addUser2(){
    SqlSession sqlSession = MybatisUtils.getSqlSession();
    UserDao mapper = sqlSession.getMapper(UserDao.class);
    Map<String, Object> map = new HashMap<String,Object>();
    map.put("userid",5);
    map.put("userName","斌");
    map.put("userPwd","123123");
    mapper.addUser2(map);
    sqlSession.commit();
    sqlSession.close();
}

总结:
Map传递参数,直接在sql中取出key即可;
对象传递参数,直接在sql中取出对象的属性即可。
多个参数使用Map或者注解!!!

  • 模糊查询
    1.在sql拼接中使用通配符防止sql注入问题;
    2.java代码执行的时候,传递通配符。
<!--
此处以1为例
-->
<select id="getUserLike" resultType="com.qiufen.pojo.User">
        select * from mybatis.user where name like "%"#{value}"%"
</select>
public void getUserLike(){
   SqlSession sqlSession = MybatisUtils.getSqlSession();
   UserDao mapper = sqlSession.getMapper(UserDao.class);
   List<User> users = mapper.getUserLike("秋");
   for (User user : users) {
       System.out.println(user);
   }
}

配置解析

1.核心配置文件

  • mybatis-config.xml

MyBatis 的配置文件包含了会深深影响 MyBatis 行为的设置和属性信息。

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

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

mybatis默认的事务管理器是JDBC,连接池:POOLED
3.属性 properties
可以通过properties属性来实现引用配置文件。
1.编写一个数据库配置文件,在resource下:
driver=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://localhost:3306/mybatis?userSSL=true&useUnicode=true&characterEncoding=UTF-8
username=root
password=123456
2.在核心配置文件中引入

<properties resource="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>
<properties resource="db.properties">
        <property name="username" value="root"/>
        <property name="pwd" value="123456"/>
</properties>
  • 可以直接引入外部文件
  • 可以在其中增加一些属性变量
  • 如果两个文件有同一字段,优先使用外部文件

4.类型别名 typeAliases

作用:用来减少类完全限定名的冗余。

1.给某个类取别名

<typeAliases>
        <typeAlias type="com.qiufen.pojo.User" alias="User"/>
</typeAliases>

2.指定一个包名

  1. MyBatis 会在包名下面搜索需要的 Java Bean。
  2. 每一个在包 domain.blog 中的 Java Bean,在没有注解的情况下,会使用 Bean 的首字母小写的非限定类名来作为它的别名。 比如domain.blog.Author 的别名为 author;若有注解,则别名为其注解值。
<typeAliases>
        <package name="com.qiufen.pojo"/>
</typeAliases>

在实体类比较少时,使用第一种方式,如果实体类多的话使用第二种。
别名前加_表示基本数据类型,不加则为引用数据类型。
5.settings

这是 MyBatis 中极为重要的调整设置,它们会改变 MyBatis 的运行时行为。

在这里插入图片描述

6.映射器 mappers
MapperRegistry:注册绑定我们的Mapper文件。
方式一:

<mappers>
        <mapper resource="com/qiufen/dao/UserMapper.xml"/>
</mappers>

方式二:使用class文件绑定注册

<mappers>
        <mapper class="com.qiufen.dao.UserDao"/>
</mappers>

使用方式二注意:

  • 接口和他的Mapper配置文件必须同名
  • 接口和他的Mapper配置文件必须在同一个包下
    注意:如果在resources资源文件夹下建立与接口路径相同的包路径来存放xxx.xml,最终在target文件夹中也会存放到一起,即这样合法。
    在这里插入图片描述

7.作用域和生命周期
在这里插入图片描述

属性名和字段名不一致的问题

1.若属性名和字段名不一致,则会导致该属性查询的结果为null。
解决方式:

  • 起别名
<select id="getUserById" parameterType="int" resultType="User">
        select id,name,pwd as password
        from mybatis.user
        where id = #{id}
</select>
  • 结果集映射 resultMap
<!--
column为数据库中的字段,property实体类中的属性
-->
<resultMap id="UserMap" type="User">
        <result column="id" property="id"/>
        <result column="name" property="name"/>
        <result column="pwd" property="password"/>
</resultMap>
<select id="getUserById" parameterType="int" resultMap="UserMap">
        select id,name,pwd
        from mybatis.user
        where id = #{id}
</select>

设置resultMap时,需要找到一个实现标签进行映射,即resultMap后面的值与resultMap标签里的id值一致。
在引用它的语句(查询,增加…标签中)使用resultMap属性即可,注意去掉resultType属性。

日志

作用:日志是我们排错的最好助手,在mybatis核心配置文件中配置日志。

<settings>
        <setting name="logImpl" value="STDOUT_LOGGING"/>
</settings>
  • STDOUT_LOGGING标准日志输出
    在这里插入图片描述
  • LOG4j
    1.使用LOG4j必须先导包。
<dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
</dependency>

2.在类路径下建立log4j.properties
#将等级为DEBUG的日志信息输出到console和file这两个目的地,console和file的定义在下面的代码
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/qiufen.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

3.配置log4j为日志的实现

<setting name="logImpl" value="LOG4j"/>

使用:
在要使用log4j的类中导入包import org.apache.log4j.Logger,日志对象logger的参数类型为当前类的class。

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

日志级别:info–>debug–>error

分页

  • limit实现分页
<select id="getUserByLimit" parameterType="map" resultMap="UserMap">
        select *
        from mybatis.user
        limit #{startIndex},#{pageSize}
</select>
public void getUserByList(){
   SqlSession sqlSession = MybatisUtils.getSqlSession();
   UserMapper mapper = sqlSession.getMapper(UserMapper.class);
   HashMap<String, Integer> map = new HashMap<>();
   map.put("startIndex",0);
   map.put("pageSize",2);
   List<User> users = mapper.getUserByLimit(map);
   for (User user : users) {
       System.out.println(user);
   }
   sqlSession.close();
}
  • RowBounds实现分页(不推荐使用)
<select id="getUserByRowBounds" resultMap="UserMap">
        select * from mybatis.user
</select>
public void getUserByRowBounds(){
   SqlSession sqlSession = MybatisUtils.getSqlSession();
   //通过rowBounds实现
   RowBounds rowBounds = new RowBounds(1, 2);
   List<User> userlist = sqlSession.selectList("com.qiufen.dao.UserMapper.getUserByRowBounds", null, rowBounds);
   for (User user : userlist) {
       System.out.println(user);
   }
   sqlSession.close();
}

使用注解开发
在这里插入图片描述
使用注解:(不需要xxx.xml配置文件)
1.注解在接口上实现

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

2.需要在核心配置文件中绑定接口

<mappers>
        <mapper class="com.qiufen.dao.UserMapper"/>
</mappers>

本质:反射机制实现;底层:动态代理。

mybais执行流程

resources获取加载全局配置文件—>实例化SqlSessionFactoryBuilder构造器—>通过XMLConfigBuilder解析配置文件流(若文件有问题,则会在这里报错)—>Configuration包含所有的配置文件信息—>实例SqlSessionFactory---->transactional事务—>创建executor执行器—>创建sqlSession—>实现CRUD
图源自狂神
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

  • 注解实现CRUD

1.在工具类创建的时候实现自动提交事务,SqlSessionFactory.openSession(true);
2.编写接口,增加注解
注意:必须将接口注册绑定到我们的核心配置文件中

增:

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

删:

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

改:

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

查:

//方法存在多个参数,所有的参数前面必须加上@param("")注解 
//查询语句中的条件值与注解同名
@Select("select * from user where id = #{id}")
User getUserById(@Param("id") int id);

3.关于@param()注解

  • 基本数据数据类型或String类型需要加上
  • 引用类型则不需要
  • 如果只有一个基本类型数据,可以忽略,但是建议加上
  • 我们在sql中引用的就是这里的@param()中设定的属性名

#{}和${}的区别为前者能防止sql注入,后者不能!!!

Lombok
使用步骤
1.在idea中安装Lombok插件
2.在项目中导入Lombok的jar包

<dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.20</version>
</dependency>

注解作用域
关于几个注解
@Data:无参构造,get,set,toString,hashcode,equals
@AllArgsConstructor:有参构造
@NoArgsConstructor:无参构造
当定义有参构造后(@AllArgsConstructor),需手动定义无参构造。

多对一处理

多个学生关联一个老师

  • 按照查询嵌套处理
<select id="getStudent" resultMap="StudentTeacher">
    select *
    from student
</select>
<resultMap id="StudentTeacher" type="Student">
	<result property="id" column="id"/>
	<result property="name" column="name"/>
	<association property="teacher" column="tid" javaType="Teacher" select="getTeacher"/>
</resultMap>
<select id="getTeacher" resultType="teacher">
	 select *
	 from teacher
	 where id = #{tid}
</select>
<!--
复杂的属性我们要单独处理
对象:association 集合:collection
-->
<!--
    查询所有的学生信息以及对应的老师信息
    思路:
    1.查询所有的学生信息
    2.根据查询出来的学生的tid,寻找对应的老师
-->
  • 按照结果嵌套处理
<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">
    <result property="id" column="sid"/>
    <result property="name" column="sname"/>
    <association property="teacher" javaType="Teacher">
        <result property="name" column="tname" />
    </association>
</resultMap>

一对多处理
一个老师有多个学生(集合)

<!--集合中的泛型信息,使用oftype获取-->

按照结果嵌套查询

<select id="getTeacherById" resultMap="TeacherStudent">
    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="TeacherStudent" type="Teacher">
   <result property="id" column="tid"/>
   <result property="name" column="tname"/>
   <collection property="students" ofType="Student">
       <result property="id" column="sid"/>
       <result property="name" column="sname"/>
       <result property="tid" column="tid"/>
   </collection>
</resultMap>

按照查询嵌套处理

<select id="getTeacher2" resultMap="TeacherStudent2">
    select * from teacher where id = #{tid}
</select>
<resultMap id="TeacherStudent2" type="Teacher">
    <collection property="students" javaType="ArrayList" ofType="Student" select="getStudentByTeacherId" column="id"/>
</resultMap>
<select id="getStudentByTeacherId" resultType="Student">
    select * from student where tid = #{tid}
</select>

小结
1.关联-association【多对一】
2.集合-collection【一对多】
3.javaType & ofType
javaType 用来指定实体类中的属性,ofType 用来指定映射到List或者集合中的pojo类型,泛型中的约束类型。

动态SQL

什么是动态SQL:动态sql就是指根据不同的条件生成不同的SQL语句。

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

在mybatis核心配置文件setings属性中设置“驼峰命名规则”,即可以将数据库经典命名,与javaBean的属性名不一致转换。

是否开启驼峰命名自动映射,即从经典数据库列名 A_COLUMN 映射到经典 Java 属性名 aColumn。

  • if
<select id="queryBlogIF" parameterType="map" resultType="blog">
    select * from blog where
    <if test="title!=null">
        title = #{title}
    </if>
    <if test="author!=null">
        and author = #{author}
    </if>
</select>

若查询条件只有author则会出现sqlerror

<where> 标签会自动
<select id="queryBlogIF" parameterType="map" resultType="blog">
    select * from blog
    <where>
        <if test="title!=null">
            title = #{title}
        </if>
        <if test="author!=null">
            and author = #{author}
        </if>
    </where>
</select>
  • choose(when,otherwise)
<select id="queryBlogChoose" parameterType="map" resultType="blog">
    select * from 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>
  • trim(where,set)
<update id="updateBlog" parameterType="map">
    update blog
    <set>
        <if test="title!=null">
            title = #{title},
        </if>
        <if test="author!=null">
            author= #{author}
        </if>
    </set>
    where id = #{id}
</update>
  • SQL片段

  • foreach

在这里插入代码片

所谓的动态SQL,本质还是SQL语句,只是我们可以在SQL层面去执行一个逻辑代码。

缓存

  • 一级缓存

测试步骤:
1.开启日志。
2.测试在一个session中查询两次相同的记录。
缓存失效的情况:
1.查询不同的东西;
2.crud操作可能会改变原数据,所以必定会刷新缓存;
3.查询不同的xxxMapper.xml;
4.手动清理缓存。
小结:一级缓存是默认存在的,只在一次sqlSession中有效,即sqlSession关闭前。

  • 二级缓存(全局缓存)
    在mybatis配置文件中显示的开启全局缓存
<setting name="cacheEnabled" value="true"/>

在要使用二级缓存的xxxMapper中开启

<cache/>
<!--可以自定属性的参数-->

问题:
1.我们需要将实体类序列化
小结:
1.只要开启了二级缓存,在同一个Mapper下就有效;
2.所有的数据都会优先存放在一级缓存中,当会话提交或关闭,才转到二级缓存。

  • 缓存原理
    图源自狂神
    在这里插入图片描述

练习题目:

p31 Role题目(推荐自己手打题目毕竟从小学就开始抄题目写作业,也不在乎再抄一次):
public interface RoleMapper {
    //获取角色列表
    public ListRole getRoleList();
    //增加角色信息
    public int add(Role role);
    //通过ID删除role
    public int deleteRoleById(@Param(id) Integer delId);
    //修改角色信息
    public int modify(Role role);
    //通过Id获取role
    public Role getRoleById(@Param(id) Integer id);
    //根据RoleCode,进行角色编码得唯一性验证
    public int roleCodeIsExist(@Param(roleCode) String roleCode);
}

p31 Bill题目(推荐自己手打题目毕竟从小学就开始抄题目写作业,也不在乎再抄一次):
public interface BillMapper {
    //根据供应商ID查询订单数量
    public int getBillCountByProviderId(@Param(providerId) Integer providerId);
    //增加订单
    public int add(Bill bill);
    //通过delId删除Bill
    public int deleteBillById(@Param(id) Integer delId);
    //同通过billId获取Bill
    public Bill getBillById(@Param(id) Integer id);
    //修改订单信息
    public int modify(Bill bill);
    //根据供应商上ID删除订单信息
    public int deleteBillByProviderId(@Param(providerId) Integer providerId);
}

p31 User题目(推荐自己手打题目毕竟从小学就开始抄题目写作业,也不在乎再抄一次):
public interface UserMapper {
    //通过userCode
    public User getLoginUser(@Param(userCode) String userCode);
    //增加用户信息
    public int add(User user);
    //通过条件查询-userList
    public ListUser getUserList(@Param(userName) String userName,@Param(userRole) Integer userRole,
                                  @Param(from) Integer currentPageNo,@Param(pageSize) Integer pageSize);
    //通过条件查询-用户表记录数
    public int getUserCount(@Param(userName) String userName,@Param(userRole) Integer userRole);
    //通过userId删除user
    public int deleteUserById(@Param(id) Integer delId);
    //通过userId获取user
    public User getUserById(@Param(id) Integer id);
    //修改用户信息
    public int modify(User user);
    //修改当前用户密码
    public int updatePwd(@Param(id) Integer id,@Param(userPassword) String pwd);
}

p31 Provider题目(推荐自己手打题目毕竟从小学就开始抄题目写作业,也不在乎再抄一次):
public interface ProviderMapper {
    //增加用户信息
    public int add(Provider provider);
    //通过条件查询-providerList
    public ListProvider getProviderList(@Param(proName) String proName,@Param(proCode) String proCode,
                                          @Param(from) Integer currentPageNo,@Param(pageSize) Integer pageSize);
    //获取供应商列表
    public ListProvider getProList();
    //通过条件查询-供应商表记录数
    public int getProviderCount(@Param(proName) String proName,@Param(proCode) String proCode);
    //通过供应商ID删除供应商信息
    public int deleteProviderById(@Param(id) Integer delId);
    //根据provider id获取供应商信息
    public Provider getProviderById(@Param(id) Integer id);
    //修改供应商
    public int modify(Provider provider);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值