idea用mybatis出现null

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);


}

spring数据库连接池的url后面添加字符串转换试试,可能是你数据库的字符编码跟java的编码不一致
jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8

看看你的配置,还有你是怎么返回的

select 里加个parameterType呢?

建议输出执行的sql语句看看问题在哪里

需要加param1或者arg0这种,不然无法识别。