ibatis主键生成方式 用序列实现自动增长 查询方式
来源:互联网 发布:aso优化推广 编辑:程序博客网 时间:2024/06/06 09:06
select seqname.nextval from dual 查询序列下一值
主键用序列来建立
1.先新建一个序列SEQ_RD_CI_APPSUBSYSTEM_ID
<selectKey resultClass="Integer" keyProperty="id"> //将值赋值给id
select SEQ_RD_CI_APPSUBSYSTEM_ID.currval from dual
</selectKey>
< selectKey> 来支持主键自动生成
keyProperty="id" 定义了主键名称 resultClass="Integer" 定义返回类型
在此处也可以将#sid#改为studentPKSequence.nextVal来实现同样的效果
<sqlMap namespace="changeReport">
<!-- 代表的是resultclass的简写 -->
<typeAlias alias="ChgDto" type="com.readysoft.report.change.model.ChgDto" />
<!-- 变更状态报表
Map<String, Object> condition = new HashMap<String, Object>();
condition.put("mt1", mt1);
condition.put("mt2", mt2);
List<ChgDto> chg_list=changeReportService.ChangeStatus(condition); 需要num和status -->
<select id="changeStatus" resultClass="ChgDto" parameterClass="Map">
select count(chg.id)num, sta.sym status
from RD_CHG chg,RD_CHGSTAT sta
where chg.status=sta.code
and chg.OPEN_DATE between #mt1# and #mt2#
group by sta.sym
</select>
<!--
OPEN_DATE
因为chg的open_date都为空 所以改为LAST_MOD_DT,
因为后者有时间 LAST_MOD_DT有时间-->
<!-- 关闭变更 ChgDto.setMt1(mt1); ChgDto.setMt2(mt2);-->
<select id="changeClosed" resultClass="Integer" parameterClass="ChgDto">
select count(chg.id) num
from RD_CHG chg,RD_CHGSTAT sta
where chg.status=sta.code
and chg.status='Closed'
and chg.CLOSE_DATE between #mt1# and #mt2#
</select>
package com.car.dao;import java.io.*;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.util.ArrayList;import java.util.List;import com.car.dto.CarInfoDTO;import com.car.dto.CarValueDTO;import com.car.jdbc.DB;import com.ibatis.sqlmap.client.SqlMapClient;public class CarValueDAOimpl_ibatis implements CarValueDAO {public static SqlMapClient sqlMapClient=null;static{Reader reader;try {reader = com.ibatis.common.resources.Resources.getResourceAsReader("SqlMapConfig.xml");sqlMapClient=com.ibatis.sqlmap.client.SqlMapClientBuilder.buildSqlMapClient(reader);reader.close();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}public void add(CarValueDTO carvaluedto) {}public void delete(int num) {}public List<CarValueDTO> findAll() {List<CarValueDTO> carList=null;try {carList=sqlMapClient.queryForList("car.selectAllCar");} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}return carList;}public CarValueDTO findBynum(int num) {//List<CarValueDTO> carList=null;CarValueDTO carValueDTO=null;try {carValueDTO=(CarValueDTO) sqlMapClient.queryForObject("car.selectcarBynum", num);} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}return carValueDTO;}public void update(CarValueDTO carvaluedto) {}public static void main(String[] args) { List<CarValueDTO> car_list=new CarValueDAOimpl_ibatis().findAll();/*for (int i = 0; i < car_list.size(); i++) {System.out.println(car_list.get(i).getCarnum());}for(CarValueDTO carValueDTO:new CarValueDAOimpl_ibatis().findAll()){System.out.println(carValueDTO.getCarnum());}*/ CarValueDTO carValueDTO = new CarValueDAOimpl_ibatis().findBynum(10);System.out.println(carValueDTO.getCarnum()+" "+carValueDTO.getCost());}}
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd" ><sqlMap namespace="car"><!-- typeAlias 给类取别名 --><typeAlias alias="Car" type="com.car.dto.CarValueDTO" /><!-- 返回对象类型的数据 --><select id="selectAllCar" resultClass="Car"> select * from carvalue</select> <select id="selectcarBynum" parameterClass="Integer" resultClass="Car"> select * from carvalue where carnum=#carnum# </select> <insert id=""> </insert> </sqlMap>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd" >
<sqlMap namespace="changeReport">
<!-- 代表的是resultclass的简写 -->
<typeAlias alias="ChgDto" type="com.readysoft.report.change.model.ChgDto" />
<!-- 变更状态报表
需要num和status -->
<select id="changeStatus" resultClass="ChgDto" parameterClass="Map">
select count(chg.id)num, sta.sym status
from RD_CHG chg,RD_CHGSTAT sta
where chg.status=sta.code
and chg.OPEN_DATE between #mt1# and #mt2#
group by sta.sym
</select>
<!--
OPEN_DATE
因为chg的open_date都为空 所以改为LAST_MOD_DT,
因为后者有时间 LAST_MOD_DT有时间-->
<!-- 关闭变更 -->
<select id="changeClosed" resultClass="Integer" parameterClass="ChgDto">
select count(chg.id) num
from RD_CHG chg,RD_CHGSTAT sta
where chg.status=sta.code
and chg.status='Closed'
and chg.CLOSE_DATE between #mt1# and #mt2#
</select>
<!-- 新建变更 -->
<select id="changeCreated" resultClass="Integer" parameterClass="ChgDto">
select count(chg.id) num1
from RD_CHG chg
where chg.OPEN_DATE between #mt1# and #mt2#
</select>
<!--变更分类 所有的 -->
<select id="changeType" resultClass="ChgDto" >
select count(chg.id) num,ctg.SYM
from RD_CHG chg,RD_CHG_CATEGORY ctg
where chg.Z_CHG_CATEGORY=ctg.ID
group by ctg.SYM
</select>
<!-- 变更分类 -->
<!-- 网络设备 -->
<select id="changeType1" resultClass="Integer" parameterClass="ChgDto">
select count(chg.id) num
from RD_CHG chg,RD_CHG_CATEGORY ctg
where chg.Z_CHG_CATEGORY=ctg.ID
where ctg.ID=61
and chg.OPEN_DATE between #mt1# and #mt2#
group by ctg.SYM
</select>
<!-- 软件产品 -->
<select id="changeType2" resultClass="Integer" parameterClass="ChgDto">
select count(chg.id) num
from RD_CHG chg,RD_CHG_CATEGORY ctg
where chg.Z_CHG_CATEGORY=ctg.ID
where ctg.ID=163
and chg.OPEN_DATE between #mt1# and #mt2#
group by ctg.SYM
</select>
<!-- 主机设备 -->
<select id="changeType3" resultClass="Integer" parameterClass="ChgDto">
select count(chg.id) num
from RD_CHG chg,RD_CHG_CATEGORY ctg
where chg.Z_CHG_CATEGORY=ctg.ID
where ctg.ID=165
and chg.OPEN_DATE between #mt1# and #mt2#
group by ctg.SYM
</select>
</sqlMap>
- ibatis主键生成方式 用序列实现自动增长 查询方式
- ibatis sql主键自动生成方式
- ibatis的主键生成方式
- ibatis的主键生成方式
- ibatis 插入数据主键依赖数据库自增长方式
- ibatis学习笔记-SQL主键生成方式
- IBatis 自动生成主键
- oracle使用序列和触发器实现主键的自动增长
- Oracle 实现主键自动增长之序列,触发器
- Oracle实现主键自增长的几种方式
- ibatis 自动生成的主键
- ibatis 自动生成的主键
- oracle实现主键自动增长
- DB2数据库查询自增长序列的2种方式
- IBatis简单实现(附主键自动生成)
- 基于Oracle,采用JDBC、Hibernate不同方式实现自定义序列主键生成
- 数据主键生成方式
- Hibernate主键生成方式
- OCP-1Z0-053-V12.02-98题
- ubuntu安装matlab及相关设置
- python sorted和sort
- struts2 HelloWorld
- 分类特征的选择和提取
- ibatis主键生成方式 用序列实现自动增长 查询方式
- ramdisk.img system.img userdata.img制作修改
- 《数据结构与算法分析》笔记------欧几里得算法求最大公约数
- 修改进程和线程优先级(todo)
- 大四生活一
- MVC与三层模型探讨
- OAuth2.0认证和授权原理
- c语言--静态数组创建树
- maven命令