idea中配置好了mybatis,可以根据是int类型的进行查找,但是如果是根据String类型的。如:name 查找的结果为null。
配置:
<?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">
select * from student
<select id="selectByName" resultMap="stud">
select * from student t where t.name =#{name}
</select>
public void test01() throws IOException {
//System.out.println("nihao");
//加载mybatis配置
String xml = "mybatis.xml";
InputStream resourceAsStream = Resources.getResourceAsStream(xml);
SqlSessionFactory build = new SqlSessionFactoryBuilder().build(resourceAsStream);
SqlSession sqlSession = build.openSession();
StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
Student student = new Student();
//student.setName("张三");
student.setName("张三");
//student.setName("张三");
Student stu = mapper.selectByName(student);
System.out.println(stu);
}