MyBatis_SelectKey使用oracle 序列插入主键
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>
MyBatis_SelectKey使用oracle 序列插入主键的更多相关文章
- MyBatis 插入主键方式和返回主键
这使用的mysql数据库,下面这种方式(没有给mysql设置自动增长)是插入主键方式: <insert id="insertBook" parameterType=" ...
- EntityFramework Core并发导致显示插入主键问题
前言 之前讨论过EntityFramework Core中并发问题,按照官网所给并发冲突解决方案以为没有什么问题,但是在做单元测试时发现too young,too siimple,下面我们一起来看看. ...
- EntityFramework Core并发导致显式插入主键问题
前言 之前讨论过EntityFramework Core中并发问题,按照官网所给并发冲突解决方案以为没有什么问题,但是在做单元测试时发现too young,too simple,下面我们一起来看看. ...
- 解决mybatisplus saveBatch 或者save 无法插入主键问题
解决mybatisplus saveBatch 或者save 无法插入主键问题 通过跟踪源码后得出结论,由于插入的表的主键不是自增的,而是手动赋值的,所以在调用saveBatch 执行的sql语句是没 ...
- Oracle序列更新为主键最大值
我们在使用 Oracle 数据库的时候,有时候会选择使用自增序列作为主键.但是在开发过程中往往会遇到一些不规范的操作,导致表的主键值不是使用序列插入的.这样在数据移植的时候就会出现各种各样的问题.当然 ...
- oracle插入主键数据、sequence和触发器
一.创建表: id number;并设为主键 name VARCHAR2(20 BYTE) 二. 插入数据 2.1 insert into addservice.test_table (id,na ...
- SQLServer 自增主键创建, 指定自增主键列值插入数据,插入主键
http://blog.csdn.net/zh2qiang/article/details/5323981 SQLServer 中含自增主键的表,通常不能直接指定ID值插入,可以采用以下方法插入. 1 ...
- 触发器 'SA.U_USER_INFO_TRG' 无效且未通过重新验证--Oracle序列
程序开发时报错:触发器 'SA.U_USER_INFO_TRG' 无效且未通过重新验证打开触发器的定义,执行其中的语句,发现序列 U_USER_INFO_SEQ 未定义.什么是序列呢?序列相当于sql ...
- Oracle序列使用:建立、删除
转自:http://www.cnblogs.com/WangPB/archive/2010/07/13/1776766.html 在开始讲解Oracle序列使用方法之前,先加一点关于Oracle cl ...
随机推荐
- github FATAL:unable to access 'https://github.com/...: Failed to connect to github.com:443; No error
今天整理github,初次使用,很多都不懂,所以遇到了克隆失败的问题,研究了大半天,后来..... 打开Git Bash,克隆已有工程到本地: $ git clone https://github.c ...
- Flask-用户角色及权限
app/models.py class Role(db.Model): __tablename__ = 'roles' id = db.Column(db.Integer, primary_key=T ...
- mysql中的存储引擎
MySQL中常用的几种存储引擎:innoDB.bdb.myisam.memory以及这几个引擎的讲解: InnoDB存储引擎: (1) innodb存储引擎该mysql表提供了事务,回滚以及系统崩溃修 ...
- 请求报文&响应报文
转自黑马程序员视频教程
- xml编辑无提示?这么破!
在学习testng这个单元测试框架时,如果咱们碰到了编辑测试套件xml,不提示的情况(有提示方便咱们学习,并且testng的测试套件定义必须按照他的dtd文件约束来),咱们可以按照下面的步骤去解决这个 ...
- js中的原型哲学思想
https://segmentfault.com/a/1190000005824449 记得当年初试前端的时候,学习JavaScript过程中,原型问题一直让我疑惑许久,那时候捧着那本著名的红皮书,看 ...
- TensorFlow L2正则化
TensorFlow L2正则化 L2正则化在机器学习和深度学习非常常用,在TensorFlow中使用L2正则化非常方便,仅需将下面的运算结果加到损失函数后面即可 reg = tf.contrib.l ...
- php 审批流程管理
1.流程管理的用法是什么样的? 2.怎么发起想要的流程? 3.审批的人要是怎么审批通过? 4.流程审核是不是要挨个走过? 一.要有数据库的内容的 肯定会有表的,首先就是用户表了,然后就是流程表,用户编 ...
- java 8:I / O 基础
原文地址:https://docs.oracle.com/javase/tutorial/essential/io/index.html 说明:每一个点都有一篇详细的文章与之对应,每翻译完一篇文章会更 ...
- curl 请求
一.Linux curl用法举例: . linux curl抓取网页: 抓取百度: curl http://www.baidu.com curl http://www.baidu.com 如发现乱码, ...