- 浏览: 2271564 次
- 性别:
- 来自: 成都
文章分类
- 全部博客 (357)
- J2EE (49)
- JavaScript (40)
- Spring (19)
- Struts (5)
- CSS (8)
- Hibernate (16)
- Java (67)
- DWR (4)
- JSON (3)
- XFIRE (1)
- Tomcat (1)
- Ant (2)
- 设计模式 (2)
- 经典收藏 (2)
- JSP (10)
- Linux (0)
- WebLogic (11)
- myeclipse (13)
- Buffalo (4)
- 文件上传相关 (1)
- oracle (33)
- html (6)
- JSTL (3)
- SVN (2)
- GIT (1)
- 孙卫琴(Java网络编程精解) (1)
- DOM4J (2)
- Swing (1)
- AJAX (1)
- Eclipse (5)
- 日志组件 (3)
- PowerDesigner (1)
- Jquery (22)
- IT技术开发相关网址 (1)
- Nutz (1)
- 其它 (1)
- Velocity (3)
- WebService (1)
- MySql (2)
- Android (1)
- Maven (2)
- Quartz (11)
- Lucene (1)
- springsource (1)
- Junit (1)
- Activiti (0)
最新评论
-
yzlseu:
拼凑,没有营养
Activiti进阶—分配组任务 -
zhangsenhao:
非常赞!代码很清楚
SpringMVC3.0+MyIbatis3.0(分页示例) -
xiamw2000:
分页写得不对,应该是 : order by ${orderNa ...
SpringMVC3.0+MyIbatis3.0(分页示例) -
sheertewtw:
...
SpringMVC:上传与下载 -
kingtoon:
...
XSS之xssprotect
参考资料
1 ibatis3.0存储过存的一些细节
http://blog.csdn.net/axman/archive/2010/03/05/5349349.aspx
2 ibatis3.X如何调用Oracle存储过程定义的in数组
http://topic.csdn.net/u/20110125/20/ade11108-761e-4b2d-96c4-fae83907ea9f.html
3 ibatis3调用存储过程
http://www.iteye.com/topic/531456
4 ibatis2.0与ibatis3.0 调用存储过程(SQL)
http://blog.sina.com.cn/s/blog_62e744e60100olfr.html
对于MyIbatis调用存储过程的一个特点是:使用Map传递参数
此示例是在前二个MyIbatis示例基础之上得来的
一 环境:XP3+Oracle10g+MyEclipse6+(Tomcat)+JDK1.5
二 Oracle存储过程
1 添加用户
2 修改用户
3 删除用户
4 查询用户
三 UserMapper.java
四 映射文件
五 测试用例
1 ibatis3.0存储过存的一些细节
http://blog.csdn.net/axman/archive/2010/03/05/5349349.aspx
2 ibatis3.X如何调用Oracle存储过程定义的in数组
http://topic.csdn.net/u/20110125/20/ade11108-761e-4b2d-96c4-fae83907ea9f.html
3 ibatis3调用存储过程
http://www.iteye.com/topic/531456
4 ibatis2.0与ibatis3.0 调用存储过程(SQL)
http://blog.sina.com.cn/s/blog_62e744e60100olfr.html
对于MyIbatis调用存储过程的一个特点是:使用Map传递参数
此示例是在前二个MyIbatis示例基础之上得来的
一 环境:XP3+Oracle10g+MyEclipse6+(Tomcat)+JDK1.5
二 Oracle存储过程
1 添加用户
create or replace procedure addUser(u_id in varchar2,u_name in varchar2,u_age in integer,u_sex in varchar2,u_address in varchar2,u_pwd in varchar2,message out varchar2) is begin insert into users (id,name,age,sex,address,password)VALUES(u_id,u_name,u_age,u_sex,u_address,u_pwd); message := '插入用户表成功'; commit; EXCEPTION WHEN OTHERS THEN message :='插入用户表失败'; end addUser;
2 修改用户
create or replace procedure updateUser(u_id in varchar2,u_name in varchar2,u_age in integer,u_sex in varchar2,u_address in varchar2,u_pwd in varchar2,message out varchar2) is begin update users u set name=u_name,age=u_age,sex=u_sex,address=u_address,password=u_pwd where id=u_id; message := '更新用户表成功'; commit; EXCEPTION WHEN OTHERS THEN message :='更新用户表失败'; end updateUser;
3 删除用户
create or replace procedure delUser(u_id in varchar2,message out varchar2) is begin delete users where id=u_id; message := '删除用户表成功'; commit; EXCEPTION WHEN OTHERS THEN message :='删除用户表失败'; end delUser;
4 查询用户
create or replace package JUV is TYPE CUR_GETUSER IS REF CURSOR; end JUV; create or replace procedure getAllUser(userList out JUV.CUR_GETUSER) as begin open userList for select * from users; end getAllUser;
三 UserMapper.java
public interface UserMapper{ public int checkUserExits(User user); public void addUser(User user); //测试存储过程插入 public void addUserProc(Map user); public List<User> getAllUser(Map map); public void selectByProc(Map<String,Integer> p); public void editUserProc(Map map); public void delUserProc(Map map); public void testCounts(Map map); }
四 映射文件
<?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.liuzd.ssm.mapper.UserMapper"> <resultMap type="com.liuzd.ssm.entity.User" id="userMap"> <id property="id" column="id" /> <result property="name" column="name" /> <result property="age" column="age" /> <result property="sex" column="sex" /> <result property="address" column="address" /> <result property="password" column="password" /> </resultMap> <select id="selectByProc" statementType="CALLABLE"> {call pp(#{x},#{y},#{z,mode=OUT,jdbcType=INTEGER})} </select> <!-- 调用存储过程 --> <select id="getAllUser" statementType="CALLABLE"> {call getAllUser(#{userList,<!-- 参数 --> mode=OUT,<!-- 参数类型 --> javaType=java.sql.ResultSet,<!-- 参数java类型 --> jdbcType=CURSOR,<!-- 参数jdbc类型 --> resultMap=userMap<!-- ResultSet需要resultMap参数 --> })} </select> <!-- 也可用insert标签 <select id="addUserProc" statementType="CALLABLE" > {call addUser(#{id},#{name},#{age},#{sex},#{address},#{password},#{message, mode=OUT,javaType=string,jdbcType=VARCHAR})} </select> --> <insert id="addUserProc" statementType="CALLABLE"> {call addUser(#{id},#{name},#{age},#{sex},#{address},#{password},#{message, mode=OUT,javaType=string,jdbcType=VARCHAR})} </insert> <update id="editUserProc" statementType="CALLABLE"> {call updateUser(#{id},#{name},#{age},#{sex},#{address},#{password},#{message, mode=OUT,javaType=string,jdbcType=VARCHAR})} </update> <delete id="delUserProc" statementType="CALLABLE"> {call delUser(#{id},#{message, mode=OUT,javaType=string,jdbcType=VARCHAR})} </delete> <select id="checkUserExits" parameterType="com.liuzd.ssm.entity.User" resultType="int"> select count(*) from users where name=#{name} and password=#{password} </select> <select id="getCounts" resultType="long"> select count(*) from users </select> <select id="getUserList" resultType="java.util.List" resultMap="userMap"> select * from users </select> <select id="getUserListByQuery" parameterType="map" resultType="java.util.List" resultMap="userMap"> select * from users <where> <if test="name != null and name != ''"> and name like CONCAT(CONCAT('%', #{name}),'%') </if> </where> </select> <select id="getUserDynamicSql" parameterType="object[]" resultType="list"> select * from users <where> <if test="array[0]">and name like #{array[0]}</if> <if test="array[1]">and sex = #{array[1]}</if> </where> </select> <select id="pageList" parameterType="map" resultType="list" resultMap="userMap"> select ttt.* from(select tt.*,rownum rn from(select * from users <where> <if test="name != null and name != ''"> <!-- 特别提醒一下, $只是字符串拼接, 所以要特别小心sql注入问题。 在开发时使用: $,方便调试sql,发布时使用: # and name like #{name}, --> and name like '%${name}%' </if> <if test="sex != null and sex != ''">and sex = #{sex}</if> </where> order by ${orderName} ${descAsc} )tt)ttt <where> <if test="startIndex != null and startIndex != ''"> rn > ${startIndex} </if> <if test="endIndex != null and endIndex != ''"> <![CDATA[ and rn <= ${endIndex} ]]> </if> </where> </select> <select id="pageCounts" parameterType="map" resultType="long"> select count(*) from users <where> <if test="name != null and name != ''"> and name like #{name} </if> <if test="sex != null and sex != ''">and sex = #{sex}</if> </where> </select> <select id="getUserListByQueryUser" parameterType="com.liuzd.ssm.entity.User" resultType="java.util.List" resultMap="userMap"> select * from users where 1=1 <if test="name != null and name != ''"> and name like CONCAT(CONCAT('%', #{name}),'%') </if> </select> <select id="getUserByUid" parameterType="string" resultType="com.liuzd.ssm.entity.User"> select * from users where id=#{id} </select> <select id="getUserByUids" parameterType="list" resultType="java.util.List" resultMap="userMap"> select * from users where id in <foreach collection="list" item="classList" open="(" separator="," close=")"> #{classList} </foreach> </select> <update id="editUser" parameterType="com.liuzd.ssm.entity.User"> update users <set> <if test="name != null and name != ''">name = #{name},</if> <if test="age > 0">age = #{age},</if> <if test="sex != null and sex != ''">sex = #{sex},</if> <if test="address != null and address != ''"> address = #{address}, </if> <if test="password != null and password != ''"> password = #{password} </if> </set> where id=#{id} <!-- update users set name=#{name},age=#{age},sex=#{sex},address=#{address},password=#{password} where id=#{id} --> </update> <insert id="addUser" parameterType="com.liuzd.ssm.entity.User"> insert into users (id,name,age,sex,address,password)VALUES(#{id},#{name},#{age},#{sex},#{address},#{password}) </insert> <delete id="delUser" parameterType="string"> delete users where id=#{id} </delete> </mapper>
五 测试用例
package com.liuzd.ssm.service; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.commons.lang3.RandomStringUtils; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.liuzd.ssm.entity.User; public class UserServiceTestProc { private static ApplicationContext ctx; @BeforeClass public static void beforeClass() { ctx = new ClassPathXmlApplicationContext("applicationContext.xml"); } @AfterClass public static void afterClass() { ctx = null; } public UserService getUserService(){ return (UserService)ctx.getBean("userService"); } @Test public void testAddUser(){ Map user = new HashMap(); user.put("age",23); user.put("id",RandomStringUtils.randomAlphanumeric(32)); user.put("name","李风"); user.put("address","南京市"); user.put("password","123"); user.put("sex","1"); getUserService().addUser2(user); System.out.println(user.get("message")); } @Test public void testUpdateUserProc(){ Map user = new HashMap(); user.put("id","7MhpyKczvyh5GaevvZdl49Box2nXvhHx"); user.put("age",98); user.put("name","李风所"); user.put("address","南京市"); user.put("password","123"); user.put("sex","1"); getUserService().editUser2(user); System.out.println(user.get("message")); } @Test public void testDelUser(){ Map map = new HashMap(); map.put("id", "rl8hxuCW21hsZnVPopKmu0VohRow7yCk"); getUserService().delUser2(map); System.out.println(map.get("message")); } @Test public void testGetUserListProc(){ Map map = new HashMap(); getUserService().getAllUser(map); List<User> list = (List<User>) map.get("userList"); for (User user : list) { System.out.println(user.getAge() + "," + user.getName()); } System.out.println("size :" + list.size()); } }
发表评论
-
【转载】Eclipse Class Decompiler——Java反编译插件
2018-06-24 11:09 1315参见:jd-eclipse 的安装和使用(最新版的) h ... -
Java多线程序源码
2016-06-24 15:04 9871、《Java多线程编程核心技术》源代码(高洪岩) 2、Jav ... -
Spring & Junit
2016-05-27 13:18 7151 测试基类(BaseJunit4Test) import ... -
XSS之xssprotect
2012-12-07 23:03 29349参考资料 1 跨网站脚本 ... -
myeclispe之图解weblogic81配置
2011-11-07 10:11 1558一 创建Weblogic81域(如下图) 注意事项:一般 ... -
Cannot forward a response that is already committed
2011-09-07 09:43 5536参考资料 1 Cannot forward a respons ... -
WebLogic之Cannot parse POST parameters of request解决方法
2011-09-06 15:31 11296参考资料 1 关于Cannot parse POST para ... -
WebLogic之weblogic.xml.jaxp.RegistrySAXTransformerFactory
2011-08-16 16:46 8679参考资料 1 Thread: java.lang.ClassC ... -
Quartz之一个任务绑定多个触发器
2011-08-15 16:27 4892参见官方示例: SchedulerFactory sf = ... -
Quartz之QuartzInitializerListener
2011-08-15 15:12 7806问题:我想在WEB容器启动时就执行任务怎么办呢 Quartz: ... -
Quartz之QuartzInitializerServlet
2011-08-15 14:39 9197问题:我想在应用程序启动之后去执行任务怎么办呢! Quartz ... -
jQuery与Java实现图片的剪切
2011-08-05 15:10 30409一 参考资料 1 jquery Jcrop 头像,logo截图 ... -
WebLogic之Session
2011-07-25 13:15 23978参考资料 1 关于WebLogic的Session丢失的问题 ... -
Frameset导致Cookies和Session丢失的原因及解决办法
2011-07-25 12:28 4293参考资料 1 Frameset导致Cookies和Sessio ... -
java,javascript对18位身份证格式的验证算法
2011-07-12 14:15 7042参考资料 1 java实现的18位身份证格式验证算法 http ... -
Quartz之CronTrigger
2011-07-11 15:01 14665参考资料 1 quartz 学习笔记 http://china ... -
Quartz之CronExpression
2011-07-08 16:15 33685参考资料 1 Spring中任务调度(Quartz篇)-续-c ... -
Quartz之SimpleTrigger
2011-07-08 15:21 27202SimpleTrigger: 它只能用于指定任务在一个特定时间 ... -
Quartz2之入门示例
2011-07-07 17:12 79056环境:XP+Myeclipse6.5+JDK1.6 q ... -
Sprint之java.util.Time
2011-07-06 16:17 1644参考资料 1 在Spring中使用JDK Timer进行任务调 ...
相关推荐
myeclipse 利用框架 spring+springmvc+springsecurity+myibatis+mysql 实现用户认证和人员增删改查的demo 1.用户认证库与人员管理库是同一个库,我这里为了方便配置文件区别为datasource和securitydatasource 2.这...
myibatis的学习例子,内容简单,一看就会,新手入门必看。
springMVC+Myibatis框架整合实例,带简易数据库操作,比较简单一目了然,有一次数据库查询操作。
myIbatis入门示例、myIbatis helloword示例、myIbatis第一个示例,一看遍懂
myibatis+spring+springmvc框架整合,带例子 ,绝对物超所值
SpringMVC3.0+MyIbatis3.0(分页示例
MyiBatis_用户手册包含以下资源: 1.iBatis2.0 开发指南中文版 2.MyiBatis3 用户指南中文版 3.MyiBatis Spring 1.0.0-snapshot 参考文档 以上都是pdf格式文档
MyIbatis3.0入门+进阶实例,直接把资源工程导入到MyEclise里就可以运行,导入到Eclipse里也可以, 包含: ---ibatis_3_学习笔记.pdf ---ibatis3__发布_入门示例.pdf 可以带你熟练使用MyIbatis3.0,实例代码对MyIbatis3.0...
springmvc集成了myibatis集成
spring mvc3.2.3+ myibatis3.2.2 分 dao service pojo mapper controllor等层,有敢于网上下载多不适用,故作一层次分明功能较全面(列表,登录验证,增加)的功能验证性web程序以为分享,因程序为功能验证性程序,...
myibatis+spring源码,包含jar包,大家的福利!
myibatis 生成oracle 对应映射文件
Spring + SpringMVC + Myibatis + Druid 整合源码,修改log4j.properties中log4j.appender.A1.File=YOUR-LOG-PATH,log4j.appender.FILE.File=YOUR-LOG-FILE
MyIbatis 一项兼容数据库存错过程的技术。与Hibernate基本一样,但他却可以支持存储过程。。这份文档详细的阐述了MyIbatis,是你学习的最佳选择。
myibatis版本为3.2.3 mysql数据库是test
SpringMvc和MyIbatis变得越来越受欢迎,MyIbatis在开发的时候比hibernate更好控制,本文就着重介绍两者的配合使用,本文关于SpringMvc的使用不多做介绍大家可以参照我的上篇SpringMvc的文章,进行了解,如有问题大家进行...
myibatis实战教程,上传只为分享
整合的struts2 spring myibatis easyUI基础框架 1.myibatis 的分页 2.异常处理机制 3.logback日记整合 4.oracle agile 整合(不需要agile,可以直接删除代码) 5.其他一些小东西的整合和整理 6.项目中有详细的注解
springMVC+myibatis的maven项目架构,真实可用的,还有word,excel的工具类,大家拿去做参考吧
springboot与myibatis集成的demo实例,简单易用,非常适合初学者参考。