MyBatis的Mapper映射文件详解
来源:互联网 发布:工程动画软件 编辑:程序博客网 时间:2024/05/16 07:37
<?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"><!-- namespace:命名空间,接口的全类名 id:唯一标示 resultType:返回值类型 #{id}:从传递过来的参数中取出id的值 --><mapper namespace="com.flx.mybatis.guigu.employee.dao.EmployeeMapper"> <!--Map传参--> <select id="getEmployeeByParamMap" resultType="com.flx.mybatis.guigu.bean.Employee" databaseId="mysql"> select * from tb1_employee where id=#{id} and last_name=#{lastName} </select> <!--注解支持的传参--> <select id="getEmployeeByIdAndLastName" resultType="com.flx.mybatis.guigu.bean.Employee" databaseId="mysql"> select * from tb1_employee where id=#{id} and last_name=#{lastName} </select> <!--这条语句在mysql环境下面使用的,databaseId--> <select id="getEmployeeById" resultType="com.flx.mybatis.guigu.bean.Employee" databaseId="mysql"> select * from tb1_employee where id = #{id} </select> <!--这条语句在oracle环境下面使用的,databaseId--> <select id="getEmployeeById" resultType="com.flx.mybatis.guigu.bean.Employee" databaseId="oracle"> select emp_id id,emp_name lastName,emp_age age from employee where emp_id = #{id} </select> <!--下面写增删改--> <!--参数类型可以省略--> <!--支持主键获取 useGeneratedKeys = true 使用自增主键获取值 keyProperty = id 将获得的id放在id属性中 --> <insert id="addEmployee" parameterType="com.flx.mybatis.guigu.bean.Employee" databaseId="mysql" useGeneratedKeys="true" keyProperty="id"> insert into tb1_employee (last_name,gender,email) VALUES (#{lastName},#{gender},#{email}) </insert> <!--oracle不支持自增,支持序列--> <insert id="addEmployee" databaseId="oracle"> <!--order: 当前sql在插入sql之前运行--> <selectKey keyProperty="id" order="BEFORE" resultType="Integer" > <!--编写查询主键的sql--> select seq_employee.nextval from dual </selectKey> <selectKey keyProperty="id" order="AFTER" resultType="Integer" > <!--insert语句执行完执行这个--> select seq_employee.currval from dual </selectKey> <!--流程:查询seq序列的sql先执行结果赋值给id,然后执行insert语句时候动态把id传给insert的sql完成主键的存储--> insert into employee (emp_id,last_name,gender,email) VALUES (#{id},#{lastName},#{gender},#{email}) </insert> <update id="updateEmployee" > update tb1_employee set last_name=#{lastName},gender=#{gender},email=#{email} where id=#{id} </update> <delete id="deleteEmployee"> delete from tb1_employee where id=#{id} </delete></mapper>
阅读全文
0 0
- MyBatis的Mapper映射文件详解
- Mybatis中Mapper映射文件详解
- mybatis映射文件mapper.xml的写法。
- mybatis的mapper映射器引入映射文件
- MyBatis的Mapper文件的标签详解
- Mybatis的mapper.xml文件详解
- Mybatis的mapper.xml文件详解
- MyBatis的映射文件mapper的select标签
- mybatis-mapper的复杂映射
- mybatis 的mapper映射文件返回一个map
- Mybatis学习之mapper映射文件中属性的含义
- mabatis 的映射文件mybatis-mapper.xml配置
- myBatis的mapper映射文件之批量处理
- MyBatis Mapper XML文件详解
- MyBatis Mapper XML文件详解
- MyBatis Mapper XML文件详解
- MyBatis Mapper XML文件详解
- Mybatis写mapper映射文件中的注意事项
- 链接错误-库冲突(libcmt.lib和libcmtd.lib)
- 多种神经网络的区别
- 离散数学基础-数理逻辑
- bzoj 3930 CQOI 选数
- Centos7下完美安装并配置mysql5.6
- MyBatis的Mapper映射文件详解
- 端午节个人赛-山东省省赛 fireworks(杨辉三角形+组合数+逆元)
- 读取手机联系人信息
- MyBatis配置文件config详解
- 区队选拔
- U盘系统盘制作(win7 32&64)
- request.getRequestDispatcher()的两个方法forward()/include()
- JavaWeb学习十七(面向接口编程)
- 【FCN实践】03 训练