zoukankan      html  css  js  c++  java
  • Mybatis用法小结

    select

    1.基本用法

    <select id="selectTableOne" resultType="com.test.entity.tableOne">
          select * from tableOne
      </select>

    2.内连接

    <sql id="joins">
            INNER JOIN rich.PSUBDAYBOOK ON rich.PMAINDAYBOOK.SALENO = rich.PSUBDAYBOOK.SALENO
            INNER JOIN rich.BITEM ON rich.PSUBDAYBOOK.ICODE = rich.BITEM.ICODE
      </sql>

    <select id="getAllTest" resultMap="BaseResultMap" parameterType="java.lang.String">
          select  *   from  test

              <include refid="joins"/>
      </select>

    2.带参数

    <select>

      select * from table

      where   id  =   #{id}

    </select>

    <select>

      select * from table

      where   id  like   CONCAT('%',#{name},'%')     //这里是mysql的写法如果是其他数据库参见::  http://w6513017.iteye.com/blog/1512761

    </select>

    update

    <update    parameterType="com.trade2cn.im.bean.testTable">

      update    testTable

      <set>

        <if test="id!=null">

          id=#{id}

        </if>

      </set>

      where name=#{name}

    </update>

    insert

    <insert id="insertTestBale" parameterType="com.test.TestTable">

      insert into test

      <trim  prefix="(" suffix=")" suffixOverrides=",">

        <if  test="id != null">

          t_id,

        </if>

        <if test="name != null">

          t_name

        </if>

      </trim>

      <trim prefix="values(" suffix=")" suffixOverrides=",">

        <if  test="id != null">

          #{id},

        </if>

        <if test="name != null">

          #{name}

        </if>

      </trim>

    </insert>

    delete

  • 相关阅读:
    前端优化,注意的一些东西
    php遍历memcache的方法
    mysql增量备份
    CI框架安装
    sphinx:received zerosized searchd response
    SEO思考:逆水行舟 不进则退
    利用GNUstep在windows下编写objectc
    Centos5.3下安装memcached
    想卖网站?我来给你指条明路
    时髦的互联网公司都在用什么技术?
  • 原文地址:https://www.cnblogs.com/wangxiangstudy/p/4917338.html
Copyright © 2011-2022 走看看