<?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. [译]在SQL查询中如何映射(替换)查询的结果?

    问题来源: https://stackoverflow.com/questions/38567366/mapping-values-in-sql-select 有一个表格,就称它Plant,它有三列: ...

  2. 有关于PHP的基础知识

    (1) l  长字符串表示,必须放在“<<<heredoc”和 “heredoc;”之间.主要是<<<,其次是也可以不使用heredoc. l  “<< ...

  3. 一个python游戏源码

    #finalPyPong.py import pygame,sys class MyBallClass(pygame.sprite.Sprite): def __init__(self,image_f ...

  4. 玩lua

    https://my.oschina.net/wangxuanyihaha/blog/186401

  5. struts2的验证

    1.原理 当浏览器向服务器提交表单数据时,在服务器端需要对表单数据的有效性进行校验. “校验方法”会在“业务方法”之前调用. 2.实现验证的两种方式 struts2校验的两种实现方法: 1. 手工编写 ...

  6. Intellij IDEA 系统路径配置

    在使用IDEA启动Tomcat的时候,会读取系统路径,默认路径可能不是我们想要的,可以修改 C:\MyPrograms\IntelliJ IDEA 14.0.1\bin\idea.properties ...

  7. MySQL之SELECT 语句详解

    本文参考实验楼的SELECT 语句详解结合自己操作部分而写成. 注意:大多数系统中,SQL语句都是不区分大小写的,但是出于严谨和便于区分保留字和变量名,在书写的时,保留字应大写,而变量名应小写.所谓的 ...

  8. Codeforces Round #531 (Div. 3) ABCDEF题解

    Codeforces Round #531 (Div. 3) 题目总链接:https://codeforces.com/contest/1102 A. Integer Sequence Dividin ...

  9. HDU 多校对抗 F Naive Operations

    Naive Operations Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 502768/502768 K (Java/Other ...

  10. 用@Component注解代替@Configuration注解,定义bean

    package com.timo.entity; import org.springframework.beans.factory.annotation.Value; import org.sprin ...