Mybatis-puls配置|Mybatis-puls配置 多表查询

mybatis-puls
mybatis-plus依赖

com.baomidou mybatis-plus-boot-starter 3.4.1

application.yml配置
server: port: 8003 spring: datasource: url: jdbc:mysql:/IP地址//数据库?serverTimezone=GMT%2B8&CharacterEncoding=utf8 username: 账号 password: 密码 mybatis-plus: # 扫描xml文件 mapper-locations: classpath:/mapper/*.xml configuration: # 控制台打印执行SQL语句 log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

启动类扫描mapper
@SpringBootApplication //扫描 @MapperScan("com.jsd.mapper") public class Springcloud03Application {public static void main(String[] args) { SpringApplication.run(Springcloud03Application.class, args); }}

pojo
User
@Data //数据库表名 @TableName("user") public class User implements Serializable { private Integer Id; private String Name; private Integer Age; private String Email; //对象 private Message message; //嵌套集合 private List messageList; }

【Mybatis-puls配置|Mybatis-puls配置 多表查询】Message
@Data @TableName("message") public class Message implements Serializable { private Integer Id; private String Message; }

UserMapper接口
//继承BaseMapper<> public interface UserMapper extends BaseMapper{List selectAll(); List selectLists(); }

UserMapper.xml文件
select a.id,a.name,a.age,a.email,b.message from user a join message b on a.id=b.idselect a.id,a.name,a.age,a.email,b.message from user a join message b on a.id=b.id

    推荐阅读