日志:log4j
1.导包
2.开启日志
在conf.xml中的configuration标签的子标签下
有一个settings标签,setting配置日志
<settings>
//开启日志,并指定使用的具体日志
<setting name= "logImpl" value="LOG4J"/>
</settings>
如果不开启日志,就会按照下面顺序去寻找日志
SLF4J ->Apache Commons Logging ->Log4j 2 ->Log4j ->JDK logging
3.编写配置日志输出文件
log4j.properties
log4j.rootLogger = DEBUG, stdout
控制日志的两种方式,stdout说明日志在那里显示(控制台),DEBUG说明输出级别
常用的4个级别:debug<info<warn<Error)打印时debug:4种全有;Info;只显示info及以上信息,以此类推 **建议:开发时设置debug,运行时设置info或以上
log4j.appender.stdout = org.apache.log4j.ConsoleAppender 显示方式:控制台普通方式
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout 平铺方式:可以是平铺,也可以是列式
log4j.appender.stdout.layout.ConversionPattern = %5p [%t] - %m%n 日志格式
**照抄就行
a.没有log4j配置文件
b. 有log4j配置文件
可以通过日志信息,相应的阅读mybatisde执行情况(观察mybatis实际执行的mysql语句以及Sql中的参数和返回结果)
***延时加载:(懒加载)
一对一、一对多、多对一、多对多
一对多:班级-学生
如果不采用延时加载(立即加载),查询时会将一和多 都查询,班级、班级中的所有学生
延时加载:如果想要暂时只查询一的以放,而多的一方 先不查询 而是在需要的时候再去查询
一对一:学生-学生证,只需要改association,不在子标签里写,在本身写,需要再写一个stucardmapper.xml,sql语句需要变,先查学生,需要的时候再查学生证
<select id="as" resultMap="xxx" parameterType="int">
select * from student
</select>
<resultMap type="student" id="xxx">
<id property="stuNo" column="id" />
<result property="stuName" column="name" />
一对一用association 属性名stucard,对应类型StudentCard,采用延时加载,在查询学生时,不立即加载学生证信息 select指定延时加载的sql语句,采用namespace+id找到对应的mapper.xml的配置的sql语句,column指定外键
<association property="stucard" javaType="StudentCard" select=” com.mapper.StudentMapper.asx” column = “cardid”>
</association>
</resultMap>
stucardmapper.xml
<mapper namespace="com.mapper.StudentMapper">
<select id="asx" resultType="stuCard" parameterType="int">
select id ,name from stucard where cardid=#{cardId}
</select>
</mapper>
最后 需要在conf.xml里配置
- 开启延时加载
<setting name= "lazeLoadingEnable" value="true"/>
2.关闭立即加载
<setting name= "aggressiveLazyLoading" value="false"/>
如果增加了mapper.xml文件,别忘了在config文件中增加配置
一对多:和一对一配置延时加载相同