@mapper注解
2024-10-20 16:46:03
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);
}
最新文章
- maven基本用法
- Spring的事件和监听器
- 重构10-Extract Method(提取方法)
- SQL Server中Delete语句表名不能用别名
- 使用Log4Net发送日志邮件 (转载)
- SQL Server 2008 R2 制作数据库结构和数据脚本
- nodejs 命令篇
- C#窗口实现最小化到系统托盘
- C# 字符串比较大小 string.Compare()方法
- UOJ#37. 【清华集训2014】主旋律
- django学习:整体思路与方向
- 解决httpclient的NoHttpResponseException异常
- php小程序登录时解密getUserInfo获取openId和unionId等敏感信息
- JavaEE正常开发怎么做
- Note of The Linux Command Line
- [原创]K8 CMS GoastGuard 密码解密工具
- (转)go语言nsq源码解读二 nsqlookupd、nsqd与nsqadmin
- [转]window下使用SetUnhandledExceptionFilter捕获让程序的崩溃
- Ethereum 源码分析之 accounts
- springMVC入门-06
热门文章
- cowsay和ansible
- 嵌入式-C语言基础:怎么样使得一个指针指向固定的区域?
- React+echarts (echarts-for-react) 画中国地图及省份切换
- shell文件报错syntax error near unexpected token &#39;$&#39;\r&#39;&#39;
- 我的Vue之旅 11 Vuex 实现购物车
- vivo浏览器的神奇操作
- python3的可迭代对象与迭代器对象
- day21 单列索引与组合索引 &; 索引的优点和使用原则 &; 视图与函数
- JDK中内嵌JS引擎介绍及使用
- 【消息队列面试】15-17:高性能和高吞吐、pull和push、各种MQ的区别