多表查询用resultType还是resultMap&Invalid bound statement (not found)解决

多表查询用resultType还是resultMap&Invalid bound statement (not found)解决

多表查询用resultType还是resultMap

如果在对应的entity里面又有自定义的类,必须用resultMap,resultMap绝对的强大,可以体现一对一( association )、一对多( collection )的关系。

比如

public class Student{
    private String id;
    private ClassRoom classroom;
}

学生类里面还有一个教室类,这是resultType处理不了的,必须用resultMap,但是如果是以下这种:

@Data
public class MenuANDEntityDTO implements Serializable {
    private Integer id;
    private String menu_name;
    private String menu_icon;
    private Integer parent_id;
    private String path;
    private Integer status;
    private Integer sort;
    private Integer eid;
    private String entity_name;
    private String entity_property;
}

全都是String这样普通的类,用resultType就够了,即使是这里面的属性不是在一张表里面的(但是在一个查询视图里面)。

还有使用resultMap的情况就是数据库字段与java实体类里面属性名不一样。需要配置对应一下。

<resultMap id="" type="">
	<result property="menuName" column="menu_name"/>
</resultMap>

property是javabean里面的属性,column是数据库里面的字段名。

Invalid bound statement (not found)

mybatis常见错误,可以用配置错误来概括,常见原因有:

  • 方法名在interface里面没有(或者写错了)

  • xml里面mapper的namespace写错了

  • xml里面result写的不对

  • 用的springboot的话

    @SpringBootApplication
    @EnableTransactionManagement
    @MapperScan(basePackages = {"edu.hebeu.fast_security_admin.mapper","edu.hebeu.fast_security_admin.dao"})
    public class FastAdminApplication {
        public static void main(String[] args) { SpringApplication.run(FastAdminApplication.class,args); }
    }
    
    

    @MapperScan要写对

  • springboot配置文件要写对

    mybatis:
      mapper-locations:
        - classpath: edu/hebeu/fast_security_admin/dao/*.xml
        - classpath*: edu/hebeu/fast_security_admin/mapper/*.xml
    

我今天碰到的问题:

在这里插入图片描述

文件夹要放对,编译出来应该是Dao.class和.xml在一个文件里面。

之前是这样的:

在这里插入图片描述

这样不行,反正我是不行,有的人可以,很玄学。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值