<?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)的更多相关文章

  1. Mybatis中的Mapper.xml映射文件sql查询接收多个参数

    ​ 我们都知道,在Mybatis中的Mapper.xml映射文件可以定制动态SQL,在dao层定义的接口中定义的参数传到xml文件中之后,在查询之前mybatis会对其进行动态解析,通常使用#{}接收 ...

  2. Mybatis入门实例

    MyBatis 简介 MyBatis 是一款优秀的持久层框架,它支持定制化 SQL.存储过程以及高级映射.MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集.MyBatis ...

  3. Mybatis入门实例解析

    写在前面:本文全程根据Mybatis官网进行入门讲解.毫无疑问,官方文档是学习这门技术最权威的资料,与此同时我们也知道官方文档对待入门小白基本上不太友好,没有入门demo.开篇就是小白们不懂的内容.有 ...

  4. mybatis 学习三 mapper xml 配置信息

    mapper xml 映射文件 1,select 标签      简单是用就这样,其中resultType 代表从这条语句中返回的期望类型的类的完全限定名或别名.也可以使用resultMap对应的id ...

  5. mybatis(三)配置mapper.xml 的基本操作

    参考:https://www.cnblogs.com/wuzhenzhao/p/11101555.html XML 映射文件 本文参考mybatis中文官网进行学习总结:http://www.myba ...

  6. 2.mybatis入门实例 连接数据库进行查询

    1.新建项目,添加mybatis和mysql的jar包 2.在mysql中新建表user[id,name,age] CREATE TABLE `users` ( `id` ) NOT NULL aut ...

  7. mybatis中的mapper.xml

    <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-/ ...

  8. 使用generator自动生成mybatis model、mapper.xml、mapper等(转)

    原文链接:http://www.cnblogs.com/lichenwei/p/4145696.html Mybatis属于半自动ORM,在使用这个框架中,工作量最大的就是书写Mapping的映射文件 ...

  9. mybatis 关联对象mapper.xml的写法

    https://github.com/zfrHJ/mybaties/blob/master/mybaties/src/com/itheima/mybatits/mapper/OrdersMapperC ...

随机推荐

  1. 修改freemarker的ftl时,不重启tomcat的办法(使用了springMVC)

    一.在使用Freemarker 时,需要在spring-mvc.xml 配置文件中作如下配置: <!-- 配置freeMarker的模板路径 --> <bean id="f ...

  2. http长连接和短连接以及连接的本职

    HTTP长连接和短连接原理浅析 本文主要讲了,http长连接本质是tcp的长连接. 网络通信过程中,建立连接的本质是什么? 连接的本质 建立连接这个词,是从早期的电话系统中来的,那个时候,“建立连接” ...

  3. springMVC js等文件找不到解决方法

    <mvc:resources mapping="/javascript/**" location="/static_resources/javascript/&qu ...

  4. 使用window.getSelection()获取div中选中文字内容及位置

    div添加一个弹出事件: $(document).ready(function () { $("#marked-area").mouseup(function (e) { $sco ...

  5. WCF 透明代理

    现在我们通过类似的原理创建一个用于模拟WCF服务端和客户端工作原理的模拟程序.[源代码从这里下载] 目录 一.基本的组件和执行流程 二.创建自定义HttpHandler实现对服务调用请求的处理 三.定 ...

  6. dechex()

    dechex() 函数把十进制转换为十六进制生成验证码的时候用到了

  7. BZOJ4318 OSU!(动态规划+概率期望)

    设f[i][0/1]为考虑前i位,第i位为0/1时的期望得分(乘以是0/1的概率).暴力转移显然.前缀和优化即可. 但是这个前缀和精度无法承受,动不动就nan. 考虑增加一位的贡献.若之前后缀1的个数 ...

  8. Robot POJ - 1376

    The Robot Moving Institute is using a robot in their local store to transport different items. Of co ...

  9. ACM模板~求逆序对的个数

    #include <map> #include <set> #include <cmath> #include <ctime> #include < ...

  10. yaml语法

    http://blog.csdn.net/mack415858775/article/details/51015662 name: Tom Smith age: 37 spouse: name: Ja ...