xxxMapper.xml
来源:互联网 发布:js 图片旋转 编辑:程序博客网 时间:2024/06/04 19:48
详细参考开发包中的开发向导文档。
BlogMapper.xml
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"><!-- namespce是查找SQL映射文件的唯一标识,必须唯一 --><mapper namespace="org.mybatis.example.BlogMapper"><!-- id是SQL映射文件中方法的唯一标识 --><select id="selectBlog" resultType="Blog">select * from Blog where id = #{id}</select></mapper>调用方法:
namespace+id方式,只需要SQL映射文件
Blog blog = session.selectOne("org.mybatis.example.BlogMapper.selectBlog", 101);
mapper类方法调用方式,只需要接口,并在接口方法上写注解和SQL语句
public interface BlogMapper {@Select(select * from blog where id=#{id})public Blog getBlog();@Insert(insert into blog(name,age) values(#{name},#{age}))public void addBlog(Blog blog);@Delete(delete from blog where id=#{id})public void deleteBlog(int id);@Update(update blog set name=#{name},age=#{age} where id=#{id})public void updateBlog(Blog blog);}
也需要再mybatis-config.xml的<mappers>中注册:
<mappers><mapper class="cn.fuzhou.mapper.BlogMapper"></mapper></mappers>
BlogMapper mapper = session.getMapper(BlogMapper.class);Blog blog = mapper.selectBlog(101);
0 0
- xxxMapper.xml
- xxxMapper.xml简单crud
- XxxMapper.xml配置
- mybatis配置详解---XXXMapper.xml
- MD5加盐和UUid,Mybatis XXXmapper.xml事例
- mybatis-config.XML配置以及,XxxMapper的CRUD
- 创建Spring-Mybatis web项目,解决IDEA下找不到XXXmapper.xml文件的问题
- MyBatis两种执行XXXMapper.xml配置文件中SQL语句的方法
- 创建Spring-Mybatis web项目,解决IDEA下找不到XXXmapper.xml文件的问题
- mybatis错误——java.io.IOException: Could not find resource com/xxx/xxxMapper.xml
- 创建Spring-Mybatis web项目,解决IDEA下找不到XXXmapper.xml文件的问题
- 无法注入XXXMapper
- mybatis XXXMapper.java中使用@Param注解
- mybatis Field xxxMapper in xxxx required a bean of type 'XXXMapper' that could not be found.
- Mybatis注解学习--xxxMapper is not known to the MapperRegistry
- Type interface XXXMapper is not known to the MapperRegistry 解决办法
- Result Maps collection already contains value for xxxMapper.BaseResultMap
- Type interface mapper.XxxMapper is not known to the MapperRegistry.
- glTexImage2D 中 format internalformat type 参数的含义
- Android保存图片到相册
- JavaScript中的数组
- OpenGL中EXT,ARB扩展的关系
- 史上最详细Windows版本搭建安装React Native环境配置
- xxxMapper.xml
- OpenGL中RBO与Texture,UBO与SSBO的异同
- Swift里的内存管理:内存管理、weak和unowned
- VUEJS实战教程第一章,构建基础并渲染出列表
- 在Windows平台上安装Node.js及NPM模块管理
- Exp Imp 导入导出常见问题解决方法-字符集的后续问题
- mysql 的基本使用
- leetcode-java-198. House Robber
- 防止连续点击打开两个重复页面的小技巧