功能:可以在任何普通类中执行原生SQL

1.配置MybatisPlus:

mybatis-plus:
  global-config:
    enable-sql-runner: true

2.执行SQL 

package com.ciih.nodred.model;

import com.baomidou.mybatisplus.extension.toolkit.SqlRunner;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.Map;

@SpringBootTest
class NodeRedTabNodeTest {

    @Test
    void test() {
        String nodeTableName = "node_red_function";
        String nodeTableId = "595cc0072a69c16f";
        Map<String, Object> stringObjectMap = SqlRunner.db().selectOne("select * from " + nodeTableName + " where id = {0}", nodeTableId);
        System.out.println(stringObjectMap);
    }
}

注意:虽然是不依赖实体,还是依赖了SpringBoot的环境,因为MybatisPlus需要依靠SpringBoot来完成初始化配置。所以无法直接用main方法来执行。
附上几个使用示例:

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐