[java论坛]log4j.properties文件配置及说明 查看:15412  回复:45

log4j.properties一般配置文件如下:


注意INFO是发布到网站站点时是INFO模式


log4j.rootLogger=INFO,Console,File


log4j.appender.Console=org.apache.log4j.ConsoleAppender

log4j.appender.Console.Target=System.out

log4j.appender.Console.layout=org.apache.log4j.PatternLayout

log4j.appender.Console.layout.ConversionPattern=[%c]%m%n


log4j.appender.File=org.apache.log4j.RollingFileAppender 

log4j.appender.File.File=mybatis.log

log4j.appender.File.MaxFileSize=10MB

log4j.appender.File.Threshold=ALL

log4j.appender.File.layout=org.apache.log4j.PatternLayout

log4j.appender.File.layout.ConversionPattern=[%p][%d{yyyy-MM-dd HH\:mm\:ss,SSS}][%c]%m%n


image.png

image.png

刚刚通过user 查出对应group_user表的group_id 

下面继续查对应group表的name名称:

同时用了sql的N+1查询,不推荐,要进行优化:

[sy.dao.UserMapper.getAll]==>  Preparing: select id, name, loginname, pwd, email, mobile, createtime from user 

[sy.dao.UserMapper.getAll]==> Parameters: 

[sy.dao.UserMapper.selectGroupUser]====>  Preparing: SELECT group_user.id, group_user.userid, group_user.groupid FROM group_user where group_user.userid=

[sy.dao.UserMapper.selectGroupUser]====> Parameters: 1(Integer)

[sy.dao.UserMapper.selectGroupUser]<====      Total: 1

[sy.dao.UserMapper.selectGroupUser]====>  Preparing: SELECT group_user.id, group_user.userid, group_user.groupid FROM group_user where group_user.userid=

[sy.dao.UserMapper.selectGroupUser]====> Parameters: 3(Integer)

[sy.dao.UserMapper.selectGroupUser]<====      Total: 1


昨天搞到现在,出现一些小bug

现在OK了,总结一下:

image.png

JUNT测试数据输出如下:

image.png

image.png

<select id="selectGroupUser" parameterType="java.lang.Integer" resultType="sy.model.GroupUser">

  SELECT

group_user.id,

group_user.userid,

group_user.groupid

FROM

group_user

where group_user.userid=#{id,jdbcType=INTEGER}

  </select>

  <resultMap type="sy.model.User" id="userResultMap" extends="BaseResultMap">

  <collection property="groupUsers" column="id" javaType="list" select="selectGroupUser" />

  </resultMap>

  <select id="getAll" resultMap="userResultMap">

  select 

  id, name, loginname, pwd, email,  mobile, createtime 

  from user

  </select>


2、进入/mybatis/src/main/java/sy/mapping/UserMapper.xml

原来简单查询为:

<select id="getAll" resultMap="BaseResultMap">

  select * from user

  </select>

修改为:


1、进入model 的user.java

package sy.model;

import java.util.List;

public class User {

//1、user里面加入中间表角色分组用户表模块

private List<GroupUser> groupUsers;

//2、Alt+Shift+s自动生成GET SET方法

    public List<GroupUser> getGroupUsers() {

return groupUsers;

}

public void setGroupUsers(List<GroupUser> groupUsers) {

this.groupUsers = groupUsers;

}

下面进行高级查询:

user通过中间表GroupUser查出用户数据含有用户的角色分组

image.png

总结一下:

image.png

image.png

当前第2页/总5页 首页 上一页 下一页 末页
ICP备案证书号: 苏ICP备14003016-2号