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);
}

最新文章

  1. maven基本用法
  2. Spring的事件和监听器
  3. 重构10-Extract Method(提取方法)
  4. SQL Server中Delete语句表名不能用别名
  5. 使用Log4Net发送日志邮件 (转载)
  6. SQL Server 2008 R2 制作数据库结构和数据脚本
  7. nodejs 命令篇
  8. C#窗口实现最小化到系统托盘
  9. C# 字符串比较大小 string.Compare()方法
  10. UOJ#37. 【清华集训2014】主旋律
  11. django学习:整体思路与方向
  12. 解决httpclient的NoHttpResponseException异常
  13. php小程序登录时解密getUserInfo获取openId和unionId等敏感信息
  14. JavaEE正常开发怎么做
  15. Note of The Linux Command Line
  16. [原创]K8 CMS GoastGuard 密码解密工具
  17. (转)go语言nsq源码解读二 nsqlookupd、nsqd与nsqadmin
  18. [转]window下使用SetUnhandledExceptionFilter捕获让程序的崩溃
  19. Ethereum 源码分析之 accounts
  20. springMVC入门-06

热门文章

  1. cowsay和ansible
  2. 嵌入式-C语言基础:怎么样使得一个指针指向固定的区域?
  3. React+echarts (echarts-for-react) 画中国地图及省份切换
  4. shell文件报错syntax error near unexpected token &#39;$&#39;\r&#39;&#39;
  5. 我的Vue之旅 11 Vuex 实现购物车
  6. vivo浏览器的神奇操作
  7. python3的可迭代对象与迭代器对象
  8. day21 单列索引与组合索引 &amp; 索引的优点和使用原则 &amp; 视图与函数
  9. JDK中内嵌JS引擎介绍及使用
  10. 【消息队列面试】15-17:高性能和高吞吐、pull和push、各种MQ的区别