自定义SQL(多表关联查询)
1.实体类
这里使用的是一个实体类还有一个VO类
UserMoney类
package com.mybatisplusstudty.entity.entity;
import lombok.Data;
import java.io.Serializable;
/**
* @Program: mybatisplus
* @Description
* @Author: 涛涛 * ^ *
* @Create: 2021-01-08 16:58
**/
@Data
public class UserMoney implements Serializable {
private Integer id;
private Double money;
private Integer userId;
private String lastName;
}
ResultVo 类
package com.mybatisplusstudty.entity.vo;
import lombok.Data;
/**
* @Program: mybatisplus
* @Description
* @Author: 涛涛 * ^ *
* @Create: 2021-01-08 17:02
**/
@Data
public class ResultVo {
private Integer id;
private Double money;
private Integer userId;
private String lastName;
}
2.数据库
3.mapper
package com.mybatisplusstudty.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mybatisplusstudty.entity.entity.User;
import com.mybatisplusstudty.entity.vo.ResultVo;
import org.apache.ibatis.annotations.Select;
import java.util.List;
/**
* @Program: mybatisplus
* @Description
* @Author: 涛涛 * ^ *
* @Create: 2021-01-07 15:12
**/
public interface UserMapper extends BaseMapper<User> {
@Select("SELECT `user`.last_name,usermoney.* FROM `usermoney`,`user` WHERE `user`.id=usermoney.userId ")
List<ResultVo> rList();
}
4.测试
System.out.println(userMapper.rList());