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 !"".equals(command.trim())">
and COMMAND=#{command}
</if>
<if test="description != null and !"".equals(description.trim())">
and DESCRIPTION like '%' #{description} '%'
</if>
</where>
</select>