搭建springboot对mysql表增删改查

安装数据库环境

安装mysql,在window环境下启动,可以用sqlyong或其它工具连接数据库

net start mysql
cd C:\Program Files\MySQL\MySQL Server 5.6\bin
mysql -u root -p
show databases;

创建表

CREATE TABLE `user` (
  `id` int(11) ,
  `name` varchar(50) ,
  PRIMARY KEY (`id`)
)

搭建Springboot环境

springboot的访问顺序:controller--Service(Interface)--MapperDao--MapperXML--数据库。

搭建springboot对mysql表增删改查_第1张图片 

编辑配置文件 application.properties 、pom.xml

编辑 application.properties 文件

# 数据库设置
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false
spring.datasource.username=test
spring.datasource.password=test

mybatis.mapper-locations=classpath:mapper/*.xml
mybatis.type-aliases-package=com.example.springboot.entity

编辑 pom.xml 文件



	4.0.0
	
		org.springframework.boot
		spring-boot-starter-parent
		3.0.0-SNAPSHOT
		 
	
	com.example
	springboot
	0.0.1-SNAPSHOT
	springboot
	
		17
	
	
		
			org.springframework.boot
			spring-boot-starter
		

		
			org.springframework.boot

你可能感兴趣的:(微服务,mysql,spring,boot,java)