mybatis sql语句的使用

log4j动态调整sql

DEBUG

INFO

ERROR

三个输出级别  DEBUG<INFO<ERROR

log4j.properties 文件

log4j.rootLogger=DEBUG,Console    //控制台输出级别   设置成DEBUG  则   DEBUG   INFO  ERROR  三个级别的信息都可以输出

log4j.appender.Console.layout=org.apache.log4j.PatternLayout                       输出布局
log4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n                输出格式

log4j.logger.org.apache=INFO     


Mybatis  通过配置文件   实现单条信息的删除

配置文件中添加         传入的参数是int类型      该delete元素的id为deleteOne

<delete id="deleteOne" parameterType="int">
      delete from MESSAGE where ID = #{_parameter}
  </delete>

java代码的实现  

sqlSession = dbAccess.getSqlSession();
      // 通过sqlSession执行SQL语句
            sqlSession.delete("Message.deleteOne", id);
            sqlSession.commit();


配置文件中   删除一批

<delete id="deleteBatch" parameterType="java.util.List">
      delete from MESSAGE where ID in(
          <foreach collection="list" item="item" separator=",">
              #{item}
          </foreach>
      )
  </delete>

java   语言实现

    sqlSession = dbAccess.getSqlSession();
            // 通过sqlSession执行SQL语句
            sqlSession.delete("Message.deleteBatch", ids);
            sqlSession.commit();


//  添加条件进行选择

<resultMap type="com.imooc.bean.Message" id="MessageResult">
    <id column="ID" jdbcType="INTEGER" property="id"/>
    <result column="COMMAND" jdbcType="VARCHAR" property="command"/>
    <result column="DESCRIPTION" jdbcType="VARCHAR" property="description"/>
    <result column="CONTENT" jdbcType="VARCHAR" property="content"/>
  </resultMap>


//参数类型  Message    返回结果类型 resultMap="MessageResult"同上

<select id="queryMessageList" parameterType="com.imooc.bean.Message" resultMap="MessageResult">
    select ID,COMMAND,DESCRIPTION,CONTENT from MESSAGE
    <where>
        <if test="command != null and !&quot;&quot;.equals(command.trim())">
            and COMMAND=#{command}
        </if>
        <if test="description != null and !&quot;&quot;.equals(description.trim())">
            and DESCRIPTION like '%' #{description} '%'
        </if>
    </where>
  </select>

 



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值