sprinboot项目创建
Springboot基础配置
在该文件下加入以下内容
spring.datasource.url=jdbc:mysql://localhost:3306/test?useSSL=true&serverTimezone=Asia/Shanghai
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.properties.hibernate.hbm2ddl.auto=update
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.show-sql= true
其中将下列框中的信息改成windows本地的信息
创建相关的包
在该package下创建controller包
同样的再次创建model包和dao包
运行
去浏览器访问8080端口
出现上图说明springboot启动成功但是没有路径
在controller包下创建java类
使用Controller
在templates包下创建html文件
将之前的HellonController与hello.html”绑定”
写完后重新运行SpringbootDemoApplication
Hello会追踪一个网页但是下面json不会
后端向前端传输数据
在model包下创建java类
上述功能是在mysql数据库中创建相应的表字段
向表中写入信息便于测试
继续编写之前的HelloController类
Alt+enter导入新的java类
上图代码是实习网页输出数据库的内容
再次重新运行SpringbootDemoApplication,访问list路径