1.标记这是一个映射接口,这样子写还是需要写xml文件

package com.atguigu.springcloud.dao;

import com.atguigu.springcloud.entities.Payment;
import com.atguigu.springcloud.entities.PaymentExample;
import java.util.List; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; @Mapper //使用了@mapper 标记这是一个映射接口
public interface PaymentMapper {
int countByExample(PaymentExample example); int deleteByExample(PaymentExample example); int deleteByPrimaryKey(Long id); int insert(Payment record); int insertSelective(Payment record); List<Payment> selectByExample(PaymentExample example); Payment selectByPrimaryKey(Long id); int updateByExampleSelective(@Param("record") Payment record, @Param("example") PaymentExample example); int updateByExample(@Param("record") Payment record, @Param("example") PaymentExample example); int updateByPrimaryKeySelective(Payment record); int updateByPrimaryKey(Payment record);
}

2:向下面这样子写的话,把mapper这个DAO交給Spring管理 ,不用再写mapper映射xml文件,自动根据这个添加@Mapper注解的接口生成一个实现类

//UserDAO
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select; import entity.User; /**
* 添加了@Mapper注解之后这个接口在编译时会生成相应的实现类
*
* 需要注意的是:这个接口中不可以定义同名的方法,因为会生成相同的id
* 也就是说这个接口是不支持重载的
*/
@Mapper
public interface UserDAO { @Select("select * from user where name = #{name}")
public User find(String name); @Select("select * from user where name = #{name} and pwd = #{pwd}")
/**
* 对于多个参数来说,每个参数之前都要加上@Param注解,
* 要不然会找不到对应的参数进而报错
*/
public User login(@Param("name")String name, @Param("pwd")String pwd);
}

@mapper注解的更多相关文章

  1. MyBatis中的@Mapper注解及配套注解使用详解(上)

    前言: 从mybatis3.4.0开始加入了@Mapper注解,目的就是为了不再写mapper映射文件(那个xml写的是真的蛋疼...).很恶心的一个事实是源码中并没有对于这个注解的详细解释 现在我们 ...

  2. MyBatis中的@Mapper注解 @Mappe与@MapperScan关系

    从mybatis3.4.0开始加入了@Mapper注解,目的就是为了不再写mapper映射文件 现在项目中的配置 public interface DemoMapper{ int deleteByPr ...

  3. @Mapper注解在springboot中无法注入

    问题① @Mapper注解报红无法注入 方法 在pom文件中添加依赖

  4. 详解 @MapperScan 注解和 @Mapper 注解

    实际上,这是一个非常简单的问题.我并没有一口回绝他,让他去百度.因为,新人都会经历这个过程.好不容易,问你一次,你直接让他百度,会打击到他的.而且,别人会觉得你摆架子. @Mapper 这个注解的定义 ...

  5. @Repository注解和@Mapper注解区别

    @Reponsitory注解 @Reponsitory使用后,在启动类上需要添加@MapperScan("xxx.xxx.xxx.mapper")注解 @Mapper注解 @Map ...

  6. Mapper注解与MapperScan注解

    1.Mapper注解 在接口类上添加@Mapper,在运行时动态代理生成实现类 @Mapper public interface UserDao { // User getUser(); } 如果想要 ...

  7. 我为什么放弃使用MyBatis3的Mapper注解

    最近在使用MyBatis3做项目.在使用注解实现Mapper的时候遇到了比较奇葩的问题:在实现数据的batch insert的时候总是报错.好不容易可以正常插入了,但是又不能返回自增的主键id到实体b ...

  8. 我为什么放弃使用mybatis3的mapper注解了

    原文链接 最近在使用MyBatis3做项目.在使用注解实现Mapper的时候遇到了比较奇葩的问题:在实现数据的batch insert的时候总是报错.好不容易可以正常插入了,但是又不能返回自增的主键i ...

  9. springboot整合mybatis完整示例, mapper注解方式和xml配置文件方式实现(我们要优雅地编程)

    一.注解方式 pom <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId& ...

  10. idea dao使用@Mapper注解 业务类使用@Autowired 注入dao 爆红问题

    实际项目跑起来无影响,但是看起来不太爽. 可以在dao类添加org.springframework.stereotype.Repository 注解 或者可以在service类中使用 javax.an ...

随机推荐

  1. 如何重启kafka

    修改配置文件 ps -ef |grep kafka kill (kafka进程号) 启动kafka [root@lecode-dev-001 bin]# ./kafka-server-start.sh ...

  2. 面试 个人摸底监测 考察考察JS三座⼤⼭ 1. 原型和原型链 2. 作⽤域与闭包 3. 异步和单线程 (第四天)

    01.如何判断⼀个变量是不是数组? let arr = [1,2,3,4] function fun(){ return arr instanceof Array } 02.如何使⽤class实现继承 ...

  3. vulnhub靶场之Chronos:1

    准备: 攻击机:虚拟机kali.本机win10. 靶机:Chronos,下载地址:https://download.vulnhub.com/chronos/Chronos.ova,下载后直接vbox打 ...

  4. 【实时数仓】Day05-ClickHouse:入门、安装、数据类型、表引擎、SQL操作、副本、分片集群

    一.ClickHouse入门 1.介绍 是一个开源的列式存储数据库(DBMS) 使用C++编写 用于在线分析查询(OLAP) 能够使用SQL查询实时生成分析数据报告 2.特点 (1)列式存储 比较: ...

  5. CSS中和颜色及渐变

    CSS可以设置的颜色 颜色名称 transparent(全透明黑色) pink yellowgreen 等指定的颜色名称 16进制 #ABCDEF 参数 含义 范围 AB 红色渠道值 00-FF CD ...

  6. 网络基础与osi七层与TCP/IP协议

     一 什么是网络 网络:计算机网络是一组计算机或网络设备通过有形 的线缆或无形的媒介如无线,连接起来,按照一定的 规则,进行通信的集合. 通信,是指人与人.人与物.物与物之间通过某种媒 介和行为进行的 ...

  7. TIE: A Framework for Embedding-based Incremental Temporal Knowledge Graph Completion 增量时序知识图谱补全论文解读

    论文网址:https://dl.acm.org/doi/10.1145/3404835.3462961 论文提出一种用增量学习思想做时序知识图谱补全(Temporal Knowledge Graph ...

  8. 搭建漏洞环境及实战——搭建DVWA漏洞环境

    DVWA是一款开源的渗透测试漏洞练习平台,其中内涵XSS.SQL注入.文件上传.文件包含.CSRF和暴力破解等各个难度的测试环境. 1.在安装时需要在数据库里创建一个数据库名,进入MySQL管理中的p ...

  9. TS学习笔记

    类型 类型 例子 描述 number 1,2,-2 任意数字 string 'hi',"hi" 任意字符串 boolean true,false 布尔值或者true false 字 ...

  10. 基本能看懂的C编译器,只有365行!

    Fabrice Bellard is a French computer programmer known for writing FFmpeg, QEMU, and the Tiny C Compi ...