MyBatis (四) 注解和存储过程
来源:互联网 发布:cxax2013车床软件 编辑:程序博客网 时间:2024/06/16 19:56
1. sql 公共片段
<sql id="publicfindemp"> select e.*,depname from employee e ,department d where d.depid=e.depid</sql>
使用 sql 公共片段:
<include refid="publicfindemp"/>
<!--3.1 分页查询和查询所有--> <select id="findEmloyee" parameterType="PageUtil" resultMap="empMap"> <choose> <!-- 分页查询 --> <when test="startrow!=0 and pagesize>0" > <include refid="publicfindemp"/> limit #{startrow},#{pagesize} </when> <!-- 查询所有 --> <otherwise> <include refid="publicfindemp"/> </otherwise> </choose> </select>
2. 存储过程原理
delimiter //create procedure pro_emp(in startrow int,in pagesize int)begin select e.*,d.depname from employee e,department d where d.depid=e.depid limit startrow,pagesize;end //delimiter;
delimiter //create procedure proc_emptotalcount(out empcount int)begin select count(*) into empcount from employee e,department d where d.depid = e.depid;end//delimiter;
在 mapper.xml 里面这么写:
1)IN
<select id="findByPrimaryKey" parameterMap="paramMap" >>>>注意要写parameterMapstatementType="CALLABLE" >>>>表示是存储过程resultType="com.pojo.Employee"> CALL EmployeeSys.proc_empbyid(?)</select><parameterMap id="paramMap" type="Employee"> <parameter property="empId" mode="IN" jdbcType="INTEGER"/> </parameterMap>
type:封装 java 对象的类型
jdbcType:参数的数据类型,必须是引用数据类型,必须是大写;
mode:存储过程的参数的类型,如果是输入参数则是IN,输出参数则是OUT;
2)OUT
<select id="getTotalcount" parameterMap="totalcountMap" statementType="CALLABLE"> CALL EmployeeSys.proc_emptotalcount(?) </select><parameterMap id="totalcountMap" type="PageUtil"> <parameter property="totalcount" mode="OUT" jdbcType="INTEGER"/></parameterMap>
3)关于 out 的 测试
System.out.println("---getTotalcount(PageUtil pageUtil)---"); PageUtil pageUtil1 = new PageUtil(1,2); mapper.getTotalcount(pageUtil1); System.out.println(pageUtil1.getTotalcount());
理解:存储过程 out 的是:out 出property=”totalcount”,并且是封装在type=”PageUtil”里面的,所以用pageUtil1.getTotalcount() 来接。select count(*) into empcount ,方法不需要返回值,直接进属性里面捞。
3)注解
在 mapper接口里面直接写sql 语句,就不需要使用 xml 文件了:
@Select("select * from project") List<Workorder> findName(); // 分页查询 @Select("select w.*,p.projectname from Workorder w,project p where p.id=w.projectid limit #{startrow},#{pagesize}") List<Workorder> findPage(PageUtil pageUtil);
阅读全文
0 0
- MyBatis (四) 注解和存储过程
- MyBatis 入门(四)--存储过程
- mybatis调用视图和存储过程
- MyBatis中调用存储过程和函数
- Mybatis调用存储过程和函数
- Mysql(四)- 存储引擎和事务,备份和恢复,索引,存储过程
- mybatis 调用存储过程(procedure)
- MyBatis 示例之存储过程(一)
- MyBatis 示例之存储过程(二)
- MyBatis 示例之存储过程(三)
- mybatis调用存储过程(plsql)
- mybatis调用存储过程(oracle)
- mybatis 主键&存储过程
- MyBatis调用存储过程
- mybatis调用存储过程
- mybatis调用存储过程
- mybatis调用存储过程
- mybatis调用存储过程
- tfs服务器重启之后, 所有tfs账户无法登陆
- myeclipse servlet的基本运用
- c#爬虫三类
- css3实现文字描边的效果
- 面向对象设计模式之六大原则
- MyBatis (四) 注解和存储过程
- redis集群安装出现redis requires Ruby version >= 2.2.2.问题
- 机器学习算法-Adaboost
- QgridLayout例子QGridLayout使用方法,qlayout添加button实例
- JAVA(JDBC)通用查询
- Ajax 之久病成医
- head first java 笔记 chapter 4~7
- Form表单提交,Ajax请求,$http请求的区别
- TI: 以cpsw为例学习设备树(内核如何调用这些参数)