# sql-builder-spring-boot **Repository Path**: dragons96/sql-builder-spring-boot ## Basic Information - **Project Name**: sql-builder-spring-boot - **Description**: sql-builder与springboot集成包 - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 3 - **Forks**: 0 - **Created**: 2022-01-29 - **Last Updated**: 2024-02-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## SqlBuilder与SpringBoot集成包 (语法类似Mybatis-Plus) ### SqlBuilder包见项目: https://gitee.com/kingons/sql-builder ### PS: 查询的SQLBuilder参数必须通过QuerySQLBuilder.INSTANCE来构建, SelectSQLBuilder 必须通过SQLBuilder.select(...)构建 1. 配置文件 application.yml ```yaml spring: datasource: url: jdbc:mysql://xxxx username: xxx password: xxx driver-class-name: xxxx # 连接池类型, 类全路径, 默认 com.zaxxer.hikari.HikariDataSource type: # 连接池配置项, 具体字段与池属性字段一直 pool: connection-timeout: 1000 ``` 2. Application类 添加 Enable 注解 ```java import club.kingon.sql.builder.spring.annotation.EnableMapper; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication @EnableMapper public class XXXApplication { public static void main(String[] args) { SpringApplication.run(XXXApplication.class, args); } } ``` 3. 编写实体类 ```java import lombok.Data; import club.kingon.sql.builder.annotation.Table; @Data @Table("xxx") public class Item { private String category; private String goodsId; private String goodsName; } ``` 4. 编写dao层接口 ```java import club.kingon.sql.builder.spring.BaseMapper; import club.kingon.sql.builder.spring.annotation.Mapper; import com.example.entity.Item; // 若接口实现了BaseMapper接口可不加@Mapper注解, 否则必须加上@Mapper注解 @Mapper public interface ItemMapper extends BaseMapper { } ``` 5. 编写控制器测试 ```java import club.kingon.sql.builder.enums.Operator; import club.kingon.sql.builder.spring.QuerySqlBuilder; import com.example.dao.ItemMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; import java.util.Arrays; @RestController public class TestController { @Autowired private ItemMapper mapper; @GetMapping("/xxx") public Object items() { return mapper.selectList( QuerySqlBuilder.INSTANCE .where("goods_id", Operator.IN, Arrays.asList(1111, 2222, 3333, 4444)) ); } } ```