以userinfo和house表为例。其中house表中的userrid对应userinfo表中的id。


首先要确定userinfo和house表的关系,一个用户可以拥有多个房子,一个房子只能对应一个用户。
以此为例进行多表查询测试。
创建项目时需注意在pom文件中导入mybatis-plus依赖:
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.1</version>
</dependency>
同时需要将mysql版本号改为5.1.26.

在YAML文件中配置连接数据库,log日志,并且配置扫描mapper文件的代码。

实体类:
UserInfo:
@TableFieId(exist=false)表示此属性不是数据库中的字段,但在项目中必须使用。
因为一个用户可以拥有多个房子,所以用List集合来装house对象。

House:

Mapper接口:
userinfoMapper:

houseMapper:
Mapper映射文件:
userinfoMapper.xml

houseMapper.xml

Service接口
userinfoService

houseService

Service实现类
userinfoServiceImpl

houseServiceImpl
控制器

进行测试


相关文章
暂无评论...

Mapper映射文件: