关联查询时,必须给每个字段起别名对应关联对象的属性么?
当前使用版本 3.5.1
该问题是如何引起的?(确定最新版也有问题再提!!!)
关联查询
重现步骤(如果有就写完整)
使用的是https://gitee.com/baomidou/mybatis-plus-samples?_from=gitee_search User.java
@Setter
@Getter
@ToString
@TableName("user")
public class User {
@TableId(type = IdType.ASSIGN_ID)
private Long id;
@TableField(value = "company_id", property = "company.company_id")
private Company company;
private String name;
private Integer age;
private String email;
}
UserMapper.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.baomidou.mybatisplus.samples.association.mapper.UserMapper">
<sql id="Base_Column_List">
t.id, t.name, t.age, t.email,
t.company_id as "company.company_id",
c.name as "company.name"
</sql>
<select id="selectUserPage" resultType="com.baomidou.mybatisplus.samples.association.entity.User">
SELECT
<include refid="Base_Column_List"/>
FROM user t
LEFT JOIN company c on t.company_id=c.company_id
<where>
${ew.sqlSegment}
</where>
</select>
</mapper>
其中的sql可否换成下面这样?
<sql id="Base_Column_List">
t.id, t.name, t.age, t.email,company.*
</sql>
<select id="selectUserPage" resultType="com.baomidou.mybatisplus.samples.association.entity.User">
SELECT
<include refid="Base_Column_List"/>
FROM user t
LEFT JOIN company on t.company_id=company .company_id
<where>
${ew.sqlSegment}
</where>
</select>
因为company.*查询到的字段是可以得到表名的
报错信息
Comment From: huayanYu
just try 每个人写法不一样