mybatis-plus自定义SQL语句中如何使用QueryWrapper.select(columns)?

How to use QueryWrapper.select(columns) in Custom SQL statements in mybatis-plus?

这是我的包装纸。

QueryWrapper<Tag> tagQueryWrapper = Wrappers.<Tag>query()
                .select("name", "count(*) num")
                .groupBy("name")
                .orderByDesc("num");

这是我的映射器。

@Component
public interface TagMapper extends BaseMapper<Tag> {

    @Select("select * from tag left join blog_tag bt on tag.id = bt.tag_id ${ew.customSqlSegment}")
    List<Tag> selectNameNum(IPage<Tag> page, @Param(Constants.WRAPPER) Wrapper<Tag> queryWrapper);

}

我不知道为什么这个 'select(column...)' 不起作用 。 它生成的SQL语句如下:

select * from tag left join blog_tag bt on tag.id = bt.tag_id GROUP BY name ORDER BY num DESC LIMIT ?,?


请帮帮我,我想知道如何用 select(column...) 替换 SQL 语句中的 '*'

鉴于 Constants.WRAPPERew,您可以在 Wrapper 中使用另一个 getter 来获取 select 列列表(类似于获取 customSqlSegment 已经)像这样:

@Component
public interface TagMapper extends BaseMapper<Tag> {

    @Select("select ${ew.sqlSelect} from tag left join blog_tag bt on tag.id = bt.tag_id ${ew.customSqlSegment}")
    List<Tag> selectNameNum(IPage<Tag> page, @Param(Constants.WRAPPER) Wrapper<Tag> queryWrapper);

}