项目搭建
docker创建mysql命令
1 2 3 4 5 6 7 8 9 10
| docker run \ -p 3307:3306 \ --name mysql8 \ --privileged=true \ -v /app/mysql8/log:/var/log/mysql \ -v /app/mysql8/data:/var/lib/mysql \ -v /app/mysql8/conf:/etc/mysql/conf.d \ -v /app/mysql8/files:/var/lib/mysql-files \ -e MYSQL_ROOT_PASSWORD=xxx \ -d mysql:8.0.27
|
其中xxx换成你要设置的密码
项目框架搭建
使用idea搭建Maven项目
image-20240629001950144
比较重要的是启动类
1 2 3 4 5 6 7 8 9 10 11 12 13
| package com.nowcoder.community;
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication public class CommunityApplication {
public static void main(String[] args) { SpringApplication.run(CommunityApplication.class, args); }
}
|
创建resource文件夹在java的同级目录
然后resource文件夹下创建配置文件application.properties
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| server.port=8080 server.servlet.context-path=/community
spring.thymeleaf.cache=false
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.url=jdbc:mysql://ip:port/community?characterEncoding=utf-8&useSSL=true&serverTimezone=Hongkong spring.datasource.username=root spring.datasource.password=xxxx spring.datasource.type=com.zaxxer.hikari.HikariDataSource spring.datasource.hikari.maximum-pool-size=15 spring.datasource.hikari.minimum-idle=5 spring.datasource.hikari.idle-timeout=30000
mybatis.mapper-locations=classpath:mapper/*.xml mybatis.type-aliases-package=com.nowcoder.community.entity mybatis.configuration.useGeneratedKeys=true mybatis.configuration.mapUnderscoreToCamelCase=true
|