MyBatis入门实例 ——Mapper.xml(zz)
<?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...persistence.usermanager.UserMapper">
<!-- 要对应到所有属性 才能使用-->
<!--<resultMap id="users" type="User">
<result property="userName" column="user_name"/>
</resultMap>-->
<!-- 这里namespace必须是UserMapper接口的路径,不然要运行的时候要报错 "is not known to the MapperRegistry" -->
<insert id="createUser" parameterType="User">
<![CDATA[ insert into
user_info (user_id, user_name, user_password,
user_email,user_role) values (#{userId},#{userName}
,#{userPassword},#{userEmail},#{userRole})]]>
<!-- 这里sql结尾不能加分号,否则报"ORA-00911"的错误 -->
</insert>
<!-- 这里的id必须和UserMapper接口中的接口方法名相同,不然运行的时候也要报错 -->
<delete id="deleteUser" parameterType="java.lang.String">
<![CDATA[ delete from user_info where id = #{id} ]]>
</delete>
<update id="updateUsers" parameterType="User">
<![CDATA[update user_info set
user_name = #{userName},
user_password = #{userPassword},
user_email = #{userEmail},
user_role = #{userRole}
where user_id = #{userId} ]]>
</update>
<select id="selectAllUsers" resultType="User">
<![CDATA[select * from user_info ]]>
</select>
<select id="selectUserById" resultType="User" parameterType="java.lang.String">
<![CDATA[select * from user_info where user_id = #{userId}]]>
</select>
<select id="selectUsers" resultType="User" parameterType="User">
<![CDATA[select * from user_info ]]>
<where>
<if test="userName!=null">
<![CDATA[And user_name like '%'||#{userName}||'%']]>
</if>
<if test="userRole!=null">
<![CDATA[And user_role like '%'||#{userRole}||'%']]>
</if>
</where>
</select>
<select id="selectUsersCount" resultType="int">
<![CDATA[select count(*) from user_info ]]>
</select>
<select id="selectUserByName" resultType="User" parameterType="java.lang.String">
<![CDATA[select * from user_info where user_name = #{userName}]]>
</select>
</mapper>
转http://blog.csdn.net/tadpole1027/article/details/6736358
MyBatis入门实例 ——Mapper.xml(zz)的更多相关文章
- Mybatis中的Mapper.xml映射文件sql查询接收多个参数
我们都知道,在Mybatis中的Mapper.xml映射文件可以定制动态SQL,在dao层定义的接口中定义的参数传到xml文件中之后,在查询之前mybatis会对其进行动态解析,通常使用#{}接收 ...
- Mybatis入门实例
MyBatis 简介 MyBatis 是一款优秀的持久层框架,它支持定制化 SQL.存储过程以及高级映射.MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集.MyBatis ...
- Mybatis入门实例解析
写在前面:本文全程根据Mybatis官网进行入门讲解.毫无疑问,官方文档是学习这门技术最权威的资料,与此同时我们也知道官方文档对待入门小白基本上不太友好,没有入门demo.开篇就是小白们不懂的内容.有 ...
- mybatis 学习三 mapper xml 配置信息
mapper xml 映射文件 1,select 标签 简单是用就这样,其中resultType 代表从这条语句中返回的期望类型的类的完全限定名或别名.也可以使用resultMap对应的id ...
- mybatis(三)配置mapper.xml 的基本操作
参考:https://www.cnblogs.com/wuzhenzhao/p/11101555.html XML 映射文件 本文参考mybatis中文官网进行学习总结:http://www.myba ...
- 2.mybatis入门实例 连接数据库进行查询
1.新建项目,添加mybatis和mysql的jar包 2.在mysql中新建表user[id,name,age] CREATE TABLE `users` ( `id` ) NOT NULL aut ...
- mybatis中的mapper.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-/ ...
- 使用generator自动生成mybatis model、mapper.xml、mapper等(转)
原文链接:http://www.cnblogs.com/lichenwei/p/4145696.html Mybatis属于半自动ORM,在使用这个框架中,工作量最大的就是书写Mapping的映射文件 ...
- mybatis 关联对象mapper.xml的写法
https://github.com/zfrHJ/mybaties/blob/master/mybaties/src/com/itheima/mybatits/mapper/OrdersMapperC ...
随机推荐
- [整理]修改git 默认编辑器为vim
git config --global core.editor vim
- lintcode-115-不同的路径 II
115-不同的路径 II "不同的路径" 的跟进问题: 现在考虑网格中有障碍物,那样将会有多少条不同的路径? 网格中的障碍和空位置分别用 1 和 0 来表示. 注意事项 m 和 n ...
- 推荐一个好的Redis GUI 客户端工具
推荐一个好的Redis GUI 客户端工具 Redis Desktop Manager
- Java IO 之 File 的创建、重命名与遍历
File表示存储设备上的一个文件或目录,使用方式查看API即可,比较简单 package org.zln.io.file; import java.io.File; /** * Created by ...
- 周记【距gdoi:105天】
月考果然很可怕,跪得要死. 然后这周搞(被老师坑)去搞某个程序,我和蔡大神和kpm分工搞(结果最后我也只是变成全程嘴炮). 这周有点闷,明明想快乐点但还是…… 进度慢得要死,后缀数组略神的东西.模仿了 ...
- BZOJ3242 [Noi2013]快餐店 【环套树 + 单调队列dp】
题目链接 BZOJ3242 题解 题意很清楚,找一点使得最远点最近 如果是一棵树,就是直径中点 现在套上了一个环,我们把环单独拿出来 先求出环上每个点外向树直径更新答案,并同时求出环上每个点外向的最远 ...
- BZOJ1093 [ZJOI2007]最大半连通子图 【tarjan缩点 + DAG最长路计数】
题目 一个有向图G=(V,E)称为半连通的(Semi-Connected),如果满足:?u,v∈V,满足u→v或v→u,即对于图中任意 两点u,v,存在一条u到v的有向路径或者从v到u的有向路径.若G ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) A
A. Bear and Game time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- 记录一发wm_concat()函数排序的问题
需求:需要将列转行之后的工序按照待执行工序号排序,如果一样按工序号排 解决方法如下: select part_no, max(ywggx) ywggx from(select mt.part_no , ...
- C# 序列化理解 2(转)
一.概述 序列化是把对象转变成流.相反的过程就是反序列化. 哪些场合用到这项技术呢? 1. 把对象保存到本地,下次运行程序时恢复这个对象. 2. 把对象传送到网络的另一台终端上,然后在此终端还原这个对 ...