SpringBoot教学资料2-Hello SpringBoot!

发布时间 2023-07-04 08:29:19作者: 临易

Hello SpringBoot! springboot的启动

1.创建springboot项目。注意选择spring-boot-starter-parent版本。版本兼容适配问题请看下列。

  • springboot1.5.9以下兼容jdk1.7

  • springboot2.x.x版本兼容jdk1.8

  • springboot3.0及以上版本兼容jdk17

  • springboot2.1之后的版本已经兼容JDK11

2.编辑properties(因为引入了SQL依赖,所以需要进行配置,否则会报错)

sql 5.0 spring.datasource.driver-class-name=com.mysql.jdbc.Driver

sql 8.0 spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

#配置数据源
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/mybatis?useUnicode=true&characterEncoding=utf-8&severTimezone=UTC
spring.datasource.user=root
spring.datasource.password=123456

 

3.在demo包下(与启动类同一层级)创建controller包,controller包下创建HelloController类。

 

package com.example.demo.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {
    @GetMapping("/hello")
    public String hello(){
        return "hello SpringBoot!";
    }
}

 

4.启动运行。

 5.打开浏览器搜索 http://localhost:8080/ ,因为没有配置网址,所以显示空白页。

 6.在8080后添加我们配置好的 /hello

http://localhost:8080/hello

 

 

成功返回了hello SpringBoot!

springboot用户与数据库交互详解

1.宏观层面 数据库与用户通过浏览器交互

 2.拆解成springboot

 3.结合案例进行讲解