zoukankan      html  css  js  c++  java
  • MyBatis之User.xml

    <?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.njupt.pojo.User">

    <select id="selectUserById" parameterType="string" resultType="com.njupt.pojo.User">
     select id ,name username , address  from user where id = #{id}
    </select>

    <select id="selectAllUsers" resultType="com.njupt.pojo.User">
     select id ,name , address  from user
    </select>

    <insert id="insertUser" parameterType="com.njupt.pojo.User">
     insert into user(id ,name , address) values(#{id},#{username},#{address})
    </insert>

    <select id="selectUserByIdForMap" parameterType="string" resultType="hashmap">
     select id ,name ,address from user where id = #{id}
    </select>

    <insert id="insertUserForMap" parameterType="hashmap">
      insert into user(id,name,address) values(#{id},#{username1},#{address});
    </insert>

    <delete id="deleteUserById" parameterType="string">
      delete from user where id = #{id}
    </delete>

    <update id="updateUserById" parameterType="com.njupt.pojo.User">
     update user set name = #{username} ,address = #{address} where id = #{id}
    </update>

    <update id="updateUserByIdForMap" parameterType="hashmap">
      update user set name = #{username2},address=#{address} where id = #{id}
    </update>

    <select id="selectUserByCondition" parameterType="com.njupt.pojo.User" resultType="com.njupt.pojo.User">
      select id , name username ,address from user where 1 = 1
      <if test="id != null">
         and id = #{id}
      </if>
      
      <if test="username != null">
         and name = #{username}
      </if>
      
      <if test="address != null">
         and address = #{address}
      </if>
    </select>

    <select id="selectUserByCondition1" parameterType="com.njupt.pojo.User" resultType="com.njupt.pojo.User">
     select id ,name as username ,address from user 
     <where>
        <if test="id != null">
            id = #{id}
        </if>
        
        <if test="username != null">
           and name = #{username}
        </if>
        
        <if test="address != null">
           and address = #{address}
        </if>
          
     </where>
    </select>
    </mapper>

  • 相关阅读:
    Maven下Flex国际化配置
    Adobe AIR and Flex
    jQuery: 刨根问底 attr and prop两个函数的区别
    HTML5[8]: 图文混排,图片与文字居中对齐
    HTML5[7]: 实现网页版的加载更多
    HTML5[6]:多行文本显示省略号
    HTML5[5]:在移动端禁用长按选中文本功能
    HTML5[4]:去除不必要的标签,完全使用css实现样式
    HTML5[3]:中文换行
    HTML5[2]:使用viewport控制手机浏览器布局
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/3049887.html
Copyright © 2011-2022 走看看