MyBatis(三) OGNL log4j

来源:互联网 发布:淘宝卖家回评大全 编辑:程序博客网 时间:2024/06/06 04:03


OGNL表达式

大小写敏感







Message.xml


可以直接在里面用方法


  <!-- id唯一 可通过namespace区分 即不同的namespace下可以有相同的id  -->  <!-- parameterType只能传一个值,只写类名,不用写变量名  -->  <!-- “&quot;“ 双引号          ”&amp;“ &    -->  <select id="queryMessageList" parameterType="com.example.bean.Message" resultMap="MessageResult">    select ID, COMMAND, DESCRIPTION, CONTENT from MESSAGE where 1 = 1    <if test="command != null and !"".equals(command.trim())">     <!-- and前面的空格都不用加 MyBatis会自动处理好 -->    and COMMAND=#{command}    </if>    <if test="description != null and !"".equals(description.trim())">     and DESCRIPTION like '%' #{description} '%'    </if>  </select>


MessageDao.java

/** * 根据查询条件查询消息列表 */public List<Message> queryMessageList(String command, String description) {DBAccess dbAccess = new DBAccess();List<Message> messageList = new ArrayList<Message>();SqlSession sqlSession = null;try {sqlSession = dbAccess.getSqlSession();Message message = new Message();message.setCommand(command);message.setDescription(description);// 通过sqlSession执行SQL语句      namespace.id// 只能传递一个变量//messageList = sqlSession.selectList("Message.queryMessageList", command);messageList = sqlSession.selectList("Message.queryMessageList", message);} catch (IOException e) { // 在Dao层处理异常e.printStackTrace();} finally {if (sqlSession != null) {sqlSession.close();}}return messageList;}



添加log4j



%d 时间 

%t 线程名

%p 级别

%-5p 占位并右对齐

%c 类的全名

%m 输出时附加的信息

%n 换行



log4j.properties


可直接放在src下


log4j.rootLogger=DEBUG,Consolelog4j.appender.Console=org.apache.log4j.ConsoleAppenderlog4j.appender.Console.layout=org.apache.log4j.PatternLayoutlog4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%nlog4j.logger.org.apache=INFO


代码:点击打开链接










原创粉丝点击