优质文章,及时送达
项目描述:在微信小程序中通过与Springboot操作数据库实现简单的增删改查,其中我是用springboot整合mybatis-plus 和mysql使用的
1. 开发前准备
1.1 前置知识
java基础
SpringBoot简单基础知识
1.2 环境参数
开发工具:IDEA
基础环境:Maven+JDK8
主要技术:SpringBoot、lombok、mybatis-plus、mysql 、微信小程序
SpringBoot版本:2.2.6
2.开发者服务器
项目结构:
2.1 初始配置
(1)pom.xml配置
org.springframework.boot
spring-boot-starter-weborg.mybatis.spring.boot
mybatis-spring-boot-starter2.1.1org.springframework.boot
spring-boot-starter-thymeleafcom.alibaba
druid1.1.14mysql
mysql-connector-java5.1.42runtimecom.baomidou
mybatis-plus-boot-starter3.1.0org.projectlombok
lomboktruecom.github.pagehelper
pagehelper-spring-boot-starter1.2.5junit
junittestorg.springframework.boot
spring-boot-starter-testtestorg.junit.vintage
junit-vintage-engine
org.springframework.boot
spring-boot-maven-plugin
(2)application.yml
# Spring Boot 的数据源配置
spring:
datasource:
name: wx
url: jdbc:mysql://localhost:3306/wx_mini_program?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertTo&useSSL=true&serverTimezone=GMT%2B8
username: root
password: root
# 使用druid数据源
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.jdbc.Driver
filters: stat
maxActive: 20 initialSize: 1 maxWait: 60000 minIdle: 1 timeBetweenEvictionRunsMillis: 60000 minEvictableIdleTimeMillis: 300000 validationQuery: select 'x' testWhileIdle: true testOnBorrow: false testOnReturn: false poolPreparedStatements: true maxPoolPreparedStatementPerConnectionSize: 20 maxOpenPreparedStatements: 20 # mybatis-plus相关配置
mybatis-plus:
# xml扫描,多个目录用逗号或者分号分隔(告诉 Mapper 所对应的 XML 文件位置)
mapper-locations: classpath:mapper/*.xml
# 以下配置均有默认值,可以不设置
global-config:
db-config:
#主键类型 AUTO:"数据库ID自增" INPUT:"用户输入ID