博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MyBatis_SelectKey使用oracle 序列插入主键
阅读量:5234 次
发布时间:2019-06-14

本文共 8934 字,大约阅读时间需要 29 分钟。

 

mapper 如下:

使用<selectkey>实现 也可以使用oracle的row 级触发器trigger实现;

 

<?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">

<mapper namespace="com.hxb.wide.demo.mapper.CCustInfoMapper">

<resultMap id="BaseResultMap" type="com.hxb.wide.demo.entity.CCustInfo">
<result column="CUST_NO" property="custNo" jdbcType="VARCHAR" />
<result column="CUST_NAME" property="custName" jdbcType="VARCHAR" />
<result column="GENDER" property="gender" jdbcType="VARCHAR" />
<result column="ID_TYPE" property="idType" jdbcType="VARCHAR" />
<result column="ID_NO" property="idNo" jdbcType="VARCHAR" />
<result column="MAIL_ADDR" property="mailAddr" jdbcType="VARCHAR" />
<result column="MOBILE" property="mobile" jdbcType="VARCHAR" />
<result column="LOGIN_PWD" property="loginPwd" jdbcType="VARCHAR" />
<result column="ADDRESS" property="address" jdbcType="VARCHAR" />
<result column="STATUS" property="status" jdbcType="VARCHAR" />
<result column="LAST_UP_DATE" property="lastUpDate" jdbcType="VARCHAR" />
<result column="LAST_LOGIN_DATE" property="lastLoginDate" jdbcType="VARCHAR" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" suffix=")" prefixOverrides="and">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">and ${criterion.condition}</when>
<when test="criterion.singleValue">and ${criterion.condition} #{criterion.value}</when>
<when test="criterion.betweenValue">and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach collection="criterion.value" item="listItem" open="(" close=")" separator=",">#{listItem}</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Update_By_Example_Where_Clause">
<where>
<foreach collection="example.oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" suffix=")" prefixOverrides="and">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">and ${criterion.condition}</when>
<when test="criterion.singleValue">and ${criterion.condition} #{criterion.value}</when>
<when test="criterion.betweenValue">and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach collection="criterion.value" item="listItem" open="(" close=")" separator=",">#{listItem}</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List">CUST_NO, CUST_NAME, GENDER, ID_TYPE, ID_NO, MAIL_ADDR, MOBILE, LOGIN_PWD, ADDRESS,
STATUS, LAST_UP_DATE, LAST_LOGIN_DATE</sql>
<select id="selectByExample" resultMap="BaseResultMap" parameterType="com.hxb.wide.demo.mapper.example.CCustInfoExample">
select
<if test="distinct">distinct</if>
<include refid="Base_Column_List" />
from C_CUST_INFO
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">order by ${orderByClause}</if>
</select>
<delete id="deleteByExample" parameterType="com.hxb.wide.demo.mapper.example.CCustInfoExample">
delete from C_CUST_INFO
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</delete>
<insert id="insert" parameterType="com.hxb.wide.demo.entity.CCustInfo">insert into C_CUST_INFO (CUST_NO, CUST_NAME, GENDER,
ID_TYPE, ID_NO, MAIL_ADDR,
MOBILE, LOGIN_PWD, ADDRESS,
STATUS, LAST_UP_DATE, LAST_LOGIN_DATE
)
values (#{custNo,jdbcType=VARCHAR}, #{custName,jdbcType=VARCHAR}, #{gender,jdbcType=VARCHAR},
#{idType,jdbcType=VARCHAR}, #{idNo,jdbcType=VARCHAR}, #{mailAddr,jdbcType=VARCHAR},
#{mobile,jdbcType=VARCHAR}, #{loginPwd,jdbcType=VARCHAR}, #{address,jdbcType=VARCHAR},
#{status,jdbcType=VARCHAR}, #{lastUpDate,jdbcType=VARCHAR}, #{lastLoginDate,jdbcType=VARCHAR}
)</insert>
<insert id="insertSelective" parameterType="com.hxb.wide.demo.entity.CCustInfo">
<selectKey resultType="java.lang.String" order="BEFORE" keyProperty="custNo">SELECT seq_cust_id.nextval AS custNo FROM dual</selectKey>
insert into C_CUST_INFO
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="custNo!=null ">CUST_NO,</if>
<if test="custName != null">CUST_NAME,</if>
<if test="gender != null">GENDER,</if>
<if test="idType != null">ID_TYPE,</if>
<if test="idNo != null">ID_NO,</if>
<if test="mailAddr != null">MAIL_ADDR,</if>
<if test="mobile != null">MOBILE,</if>
<if test="loginPwd != null">LOGIN_PWD,</if>
<if test="address != null">ADDRESS,</if>
<if test="status != null">STATUS,</if>
<if test="lastUpDate != null">LAST_UP_DATE,</if>
<if test="lastLoginDate != null">LAST_LOGIN_DATE,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="custNo!=null">#{custNo,jdbcType=VARCHAR},</if>
<if test="custName != null">#{custName,jdbcType=VARCHAR},</if>
<if test="gender != null">#{gender,jdbcType=VARCHAR},</if>
<if test="idType != null">#{idType,jdbcType=VARCHAR},</if>
<if test="idNo != null">#{idNo,jdbcType=VARCHAR},</if>
<if test="mailAddr != null">#{mailAddr,jdbcType=VARCHAR},</if>
<if test="mobile != null">#{mobile,jdbcType=VARCHAR},</if>
<if test="loginPwd != null">#{loginPwd,jdbcType=VARCHAR},</if>
<if test="address != null">#{address,jdbcType=VARCHAR},</if>
<if test="status != null">#{status,jdbcType=VARCHAR},</if>
<if test="lastUpDate != null">#{lastUpDate,jdbcType=VARCHAR},</if>
<if test="lastLoginDate != null">#{lastLoginDate,jdbcType=VARCHAR},</if>
</trim>
</insert>
<select id="countByExample" parameterType="com.hxb.wide.demo.mapper.example.CCustInfoExample" resultType="java.lang.Integer">
select count(*) from C_CUST_INFO
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</select>
<update id="updateByExampleSelective" parameterType="map">
update C_CUST_INFO
<set>
<if test="record.custNo != null">CUST_NO = #{record.custNo,jdbcType=VARCHAR},</if>
<if test="record.custName != null">CUST_NAME = #{record.custName,jdbcType=VARCHAR},</if>
<if test="record.gender != null">GENDER = #{record.gender,jdbcType=VARCHAR},</if>
<if test="record.idType != null">ID_TYPE = #{record.idType,jdbcType=VARCHAR},</if>
<if test="record.idNo != null">ID_NO = #{record.idNo,jdbcType=VARCHAR},</if>
<if test="record.mailAddr != null">MAIL_ADDR = #{record.mailAddr,jdbcType=VARCHAR},</if>
<if test="record.mobile != null">MOBILE = #{record.mobile,jdbcType=VARCHAR},</if>
<if test="record.loginPwd != null">LOGIN_PWD = #{record.loginPwd,jdbcType=VARCHAR},</if>
<if test="record.address != null">ADDRESS = #{record.address,jdbcType=VARCHAR},</if>
<if test="record.status != null">STATUS = #{record.status,jdbcType=VARCHAR},</if>
<if test="record.lastUpDate != null">LAST_UP_DATE = #{record.lastUpDate,jdbcType=VARCHAR},</if>
<if test="record.lastLoginDate != null">LAST_LOGIN_DATE = #{record.lastLoginDate,jdbcType=VARCHAR},</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExample" parameterType="map">
update C_CUST_INFO
set CUST_NO = #{record.custNo,jdbcType=VARCHAR},
CUST_NAME = #{record.custName,jdbcType=VARCHAR},
GENDER = #{record.gender,jdbcType=VARCHAR},
ID_TYPE = #{record.idType,jdbcType=VARCHAR},
ID_NO = #{record.idNo,jdbcType=VARCHAR},
MAIL_ADDR = #{record.mailAddr,jdbcType=VARCHAR},
MOBILE = #{record.mobile,jdbcType=VARCHAR},
LOGIN_PWD = #{record.loginPwd,jdbcType=VARCHAR},
ADDRESS = #{record.address,jdbcType=VARCHAR},
STATUS = #{record.status,jdbcType=VARCHAR},
LAST_UP_DATE = #{record.lastUpDate,jdbcType=VARCHAR},
LAST_LOGIN_DATE = #{record.lastLoginDate,jdbcType=VARCHAR}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<select id="selectByExampleWithRowbounds" resultMap="BaseResultMap" parameterType="com.hxb.wide.demo.mapper.example.CCustInfoExample" resultType="com.hxb.wide.demo.entity.CCustInfo">
select
<if test="distinct">distinct</if>
<include refid="Base_Column_List" />
from C_CUST_INFO
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">order by ${orderByClause}</if>
</select>
<select id="selectByPrimaryKey" />
<delete id="deleteByPrimaryKey" />
<update id="updateByPrimaryKeySelective" />
<update id="updateByPrimaryKey" />
<delete id="deleteByCustName" parameterType="com.hxb.wide.demo.entity.CCustInfo">delete from C_CUST_INFO where CUST_NAME = #{custName,jdbcType=VARCHAR}</delete>
<delete id="deleteByCustNo">delete from C_CUST_INFO where CUST_NO = #{custNo,jdbcType=VARCHAR}</delete>
<select id="queryByCustNo" parameterType="java.lang.String" resultMap="BaseResultMap" >select * from C_CUST_INFO where CUST_NO = #{custNo,jdbcType=VARCHAR}</select>
</mapper>

 

转载于:https://www.cnblogs.com/anyehome/p/7986264.html

你可能感兴趣的文章
[转]ASP数组全集,多维数组和一维数组
查看>>
C# winform DataGridView 常见属性
查看>>
逻辑运算和while循环.
查看>>
Nhiberate (一)
查看>>
c#后台计算2个日期之间的天数差
查看>>
安卓开发中遇到的小问题
查看>>
ARTS打卡第3周
查看>>
linux后台运行和关闭SSH运行,查看后台任务
查看>>
cookies相关概念
查看>>
CAN总线波形中ACK位电平为什么会偏高?
查看>>
MyBatis课程2
查看>>
桥接模式-Bridge(Java实现)
查看>>
svn客户端清空账号信息的两种方法
查看>>
springboot添加servlet的两种方法
查看>>
java的Array和List相互转换
查看>>
layui父页面执行子页面方法
查看>>
如何破解域管理员密码
查看>>
Windows Server 2008 R2忘记管理员密码后的解决方法
查看>>
IE11兼容IE8的设置
查看>>
windows server 2008 R2 怎么集成USB3.0驱动
查看>>