Spring Boot MyBatis-Plus setSql() 方法用法

MyBatis-Plus Spring Boot About 736 words

自定义 SQL 片段

setSql(String setSql, Object... params)

boolean success = pointsService.lambdaUpdate()
        .eq(Points::getUserId, uid)
        .setSql("balance = balance - {0}", points)
        .setSql("expiring = expiring - {0}", points)
        .update(new Points());

setSql(boolean condition, String setSql, Object... params)

boolean condition = mpUser.getTotalSignDate() == null;

boolean success = mpUserService.lambdaUpdate()
        .eq(MpUser::getId, userId)
        .set(MpUser::getLastSignDate, date)
        .setSql(condition, "total_sign_date = 1")
        .setSql(!condition, "total_sign_date = total_sign_date + 1")
        .update(new MpUser());

与 apply() 方法区别

setSql仅用于update语句。

apply可用于selectupdatedeletewhere等多个语句。

Views: 110 · Posted: 2025-09-28

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh