[Java] 纯文本查看 复制代码
public class UserDaoTest{
private SqlSessionFactory sqlSessionFactory;
//此方法在执行testFindUserById() 之前执行
@Before
public void setUp() throws Exception {
//创建sqlSessionfactory
//MyBatis配置文件
String resource="SqlMapConfig.xml";
//得到配置文件流
InputStream inputStream=Resources.getResourceAsStream(resource);
//创建会话工厂,传入MyBatis的配置文件信息
SqlSessionFactory sqlSessionFactory=new SqlSessionFactoryBuilder().build(inputStream);
}
@Test
public void testFindUserById() throws Exception {
//创建UserDao的对象
UserDao userDao =new UserDaoImpl(sqlSessionFactory);
//调用UserDao的方法
User user =userDao.findUserById(4);
System.out.println(user.toString());
}
}
[Java] 纯文本查看 复制代码
public class UserDaoTest{
private SqlSessionFactory sqlSessionFactory;
//此方法在执行testFindUserById() 之前执行
@Before
public void setUp() throws Exception {
//创建sqlSessionfactory
//MyBatis配置文件
String resource="SqlMapConfig.xml";
//得到配置文件流
InputStream inputStream=Resources.getResourceAsStream(resource);
//创建会话工厂,传入MyBatis的配置文件信息
sqlSessionFactory=new SqlSessionFactoryBuilder().build(inputStream);
}
@Test
public void testFindUserById() throws Exception {
//创建UserDao的对象
UserDao userDao =new UserDaoImpl(sqlSessionFactory);
//调用UserDao的方法
User user =userDao.findUserById(4);
System.out.println(user.toString());
}
}