小慧机~~~ 2021-04-08 21:23 采纳率: 100%
浏览 32
已结题

研究半天没有找出来问题出在哪里

mapper.xml

<select id="selectlike" resultType="com.rj.entity.Student">
    select * from student WHERE sname LIKE '${sname}%'
</select>
<select id="selectwhere" resultType="com.rj.entity.Student">
    select * from  student
    <where>
        <if test="stu.sname !=null and stu.sname !=''">
            sname LIKE '${stu.sname}%'
        </if>
        <if test="stu.sno !=null and stu.sno !=''">
            AND sno LIKE '${stu.sno}%'
        </if>
    </where>
</select>

dao

public  List<Student> selectwhere(@Param("stu") Student stu);

service

public  List<Student> selectwhere(Student stu) throws IOException;

serviceimpl

public List<Student> selectwhere(Student stu) throws IOException {
    SqlSession session = MyBatisUtil.getSqlSession();
    //创建dao层对象 代理模式(反射)
    IStudentDao dao=session.getMapper(IStudentDao.class);
    //调用dao层提供的方法
    List<Student> list =dao.selectwhere(stu);
    //关闭session
    MyBatisUtil.close();
    return list;
}

testmain

//调用service
IStudentService service = new IStudentServiceImpl();
//List<Student> students = service.selectAllList();
Student student=new Student();
student.setSname("王");
student.setSno("19");
//模糊查询
// List<Student> students=service.selectlike(student);
//多条件查询
List<Student> students=service.selectwhere(student);
//打印输出
System.out.println(students);

总是报这个错是怎么会是呢

Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: org.apache.ibatis.builder.BuilderException: Error evaluating expression 'stu.sno !=null and stu.sno !='''. Cause: org.apache.ibatis.ognl.NoSuchPropertyException: com.rj.entity.Student.sno
### Cause: org.apache.ibatis.builder.BuilderException: Error evaluating expression 'stu.sno !=null and stu.sno !='''. Cause: org.apache.ibatis.ognl.NoSuchPropertyException: com.rj.entity.Student.sno

  • 写回答

1条回答 默认 最新

  • 风雨编码路 2021-04-09 16:56
    关注

    org.apache.ibatis.ognl.NoSuchPropertyException: com.rj.entity.Student.sno,看看Student对象的sno属性有没有get方法

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 2月23日
  • 已采纳回答 2月15日

悬赏问题

  • ¥15 在国外文献网站里点击view pdf 加载异常缓慢甚至加载不出来。
  • ¥50 python批量提取发票的信息
  • ¥15 mysql安装,初始化数据库失败
  • ¥15 虚幻五引擎内容如何上传至网盘?
  • ¥15 使用mmpose库时出现了问题
  • ¥15 IRI2016模型matlab运行报错
  • ¥50 bat怎么设置电脑后台自动点击网页指定词运行脚本,输入指定网页链接,指定点击词,指定间隔时间,指定网页出现的词,指定网页出现词出现后后点击锁定,放在后台运行不影响前台鼠标工作
  • ¥20 20CrMnMo的高温变形抗力
  • ¥15 RTX3.6 5565驱动中断报错
  • ¥50 带防重放token(Antireplay-Token)的网站怎么用Python发送请求