- 当前案例地址
- 构建gradle项目
- 配置字符集、注解生效激活、Java Compiler
- 使用IDE自带的gradle
- 测试打包
- 参考
- 拉取依赖
dependencies {testCompile group: \'junit\', name: \'junit\', version: \'4.12\'implementation \'org.springframework.boot:spring-boot-starter\'testImplementation group: \'org.springframework.boot\', name: \'spring-boot-starter-test\', version: \'2.5.2\'implementation group: \'org.springframework.boot\', name: \'spring-boot-starter-web\', version: \'2.5.4\'implementation group: \'org.springframework.boot\', name: \'spring-boot-devtools\', version: \'2.5.4\'implementation \'org.projectlombok:lombok:1.18.8\'annotationProcessor \'org.projectlombok:lombok:1.18.8\'implementation group: \'mysql\', name: \'mysql-connector-java\', version: \'8.0.23\'implementation group: \'com.alibaba\', name: \'druid\', version: \'1.2.6\'implementation group: \'com.baomidou\', name: \'mybatis-plus-boot-starter\', version: \'3.4.3\'implementation group: \'com.alibaba\', name: \'fastjson\', version: \'1.2.76\'}
- 配置yml
server:port: 8080spring:application:name: gradle-demo01datasource:type: com.alibaba.druid.pool.DruidDataSourcedriver-class-name: com.mysql.cj.jdbc.Driverurl: jdbc:mysql://192.168.96.192:3306/dbtest?useUnicode=true&characterEncoding=UTF-8username: rootpassword: 123456mvc:view:suffix: ".html"mybatis:configuration:map-underscore-to-camel-case: truemapperLocations: classpath:mapper/*.xmllogging:level:com:chnq:gradledemo01: debug
- 配置启动类
import org.mybatis.spring.annotation.MapperScan;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication@MapperScan("com.chnq.gradledemo01.mapper")public class GradleDemo01Application {public static void main(String[] args) {SpringApplication.run(GradleDemo01Application.class, args);}}
-
创建数据库
-
编写配置类
import com.baomidou.mybatisplus.annotation.DbType;import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;import org.mybatis.spring.annotation.MapperScan;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import org.springframework.transaction.annotation.EnableTransactionManagement;@EnableTransactionManagement@Configuration@MapperScan("com.chnq.gradledemo01.mapper")public class MybatisPlusConfig {@Beanpublic MybatisPlusInterceptor mybatisPlusInterceptor() {MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));return interceptor;}}
- 编写实体类、mapper、service、controller