mybatis入门,查询不到结果
domain如下:
package com.itcast.mybatis.domain;
public class User {
private String id;
private String name;
private String address;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
@Override
public String toString() {
return "{id:" + id + ",name:" + name + ",address:" + address + "}";
}
}
User.xml如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!-- namespace写什么都行,但是要求是唯一的,所以一般写成下面的格式 -->
<mapper namespace="com.itcast.mybatis.domain.User">
<!-- 根据id查询user ,id的值是随意的,最好有意义-->
<!--ibatIS使用的占位符是#id# -->
<!-- id:当前sql语句的唯一标示 parameterType:参数类型 resultType:结果类型(返回值类型) -->
<!-- string要小写,是个别名。全名写成java.lang.String -->
<!-- resultMap后面的类型写全路径-->
<select id="selectUserById" parameterType="string"
resultType="com.itcast.mybatis.domain.User">
select * from myuser where id=#{id}
</select>
</mapper>
sqlMapConfig.xml如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC" />
<dataSource type="POOLED">
<property name="driver" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl" />
<property name="username" value="scott" />
<property name="password" value="test" />
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource="com/itcast/mybatis/domain/User.xml"/>
</mappers>
</configuration>
测试类如下:
package com.itcast.mybatis.test;
import
java.io.IOException;
import java.io.InputStream;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;
import com.itcast.mybatis.domain.User;
public class MybatisTest {
@Test
public void test() throws Exception{
String resourse="sqlMapConfig.xml";
InputStream inputStream=Resources.getResourceAsStream(resourse);
SqlSessionFactory sf=new SqlSessionFactoryBuilder().