1.resourceCreate a configuration file log4j.properties
Copy the following code into it
# Global logging configuration
log4j.rootLogger=ERROR, stdout
# MyBatis logging configuration…
#Modify the following package to#log4j.logger.log4j.logger.com.xmg.mybatis=TRACE
# Console output…
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] – %m%n
Two, class MybatisUtils – ()
1、Change to SqlSession session =MybatisUtil.openSession();
—————————————–Alias name————————————————–
</typeAliases>
2.” and thenUserMapper.xmlChange all of them into
parameterType=”User”
resultType=”User”
Two.mybatis
username=root
password=123
2.” and thenmybaties-config.xml
Replace the following:
<!– Database connection pool –>
<dataSource type=“POOLED”>
<property name=“driver” value=“${driver}“ />
<property name=“url” value=“${url}“ />
<property name=“username” value=“${username}“ />
<property name=“password” value=“${password}“ />
</dataSource>
3.” in song styledb.propertiesIncoming MybatiesUtil
(3.1)The first way!!!!!!
Properties props = new Properties();
props.load(Resources.getResourceAsStream(“db.properties”));
” and thenpropsAdd to second properties
sf = new SqlSessionFactoryBuilder(). build(Resources.getResourceAsStream(“mybatis-config.xml”),props);
(3.2)The second way!!!!!!
” directly “mybaties-config.xmlAdd this sentence inside.
<!– adoptmybatiesvoid add(User u);
//fafa.bean.UserMapper.update
void update(User u);
//fafa.bean.UserMapper.get
User get(Long id);
//fafa.bean.UserMapper.delete
void delete(Long id);
//fafa.bean.UserMapper.list
List<User> list();
2.Then put the HelloMapperTest.java in the
session.insert(“fafa.bean.UserMappersave”,u);
UserMapper mapper = session.getMapper(UserMapper.class);
mapper.add(u);