SpringBoot------初始SpringBoot

1.spring development:

  • Servlet + jsp: Native Development, is very troublesome, web.xml code or there will be a lot of duplicate content;
  • Spring Spring: 2003 ====> 2020, which all things are configuration files. Many integrated framework or do some large-scale projects, will cause the entire program and project very bloated; throughout the configuration file; web.xml, tomcat must be configured, lib also need to rely on management
  • SpringBoot: To simplify the configuration file , just like Spring upgraded version of the original lot of things you need to manually configure, and now only need to automatically configure!

In Spring, start a service, like a startup than helloworld

2 write a program springboot

Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description

Write HelloController

@RestController
public class HelloController {

    @RequestMapping("/hello")
    public String hello(){
        return "I miss you,my lover";
    }
}

Start the main startup class, test access port 8080

Note the point: the new Controller class must master boot child in the class of otherwise inaccessible
Here Insert Picture Description

3. Customize Start Logo

  • 1. Under the new resource banner.txtfile
  • 2. Generate your own logo on the line to create website:https://www.bootschool.net/ascii
  • 3. Start the master-class test start
    Here Insert Picture Description

4. Start writing your own master class

  • The structure does not change, increased @SpringBootApplicationnotes and use its run method
@SpringBootApplication
public class myApplication {

    public static void main(String[] args) {
        SpringApplication.run(myApplication.class,args);
    }
}

5. Dependence

Father dependence

<!-- 父依赖作用分析
1、自动帮你管理依赖,里面包含了几乎常用的所有依赖,如果你需要的依赖在这里面有,你就不要配置了,如果没有再配置
2、插件和资源过滤的自动管理;
-->
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.2.5.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

Starter, the official website:https://docs.spring.io/spring-boot/docs/2.2.5.RELEASE/reference/html/using-spring-boot.html#using-boot

<dependency>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot-starter</artifactId>
    <version>2.1.1</version>
</dependency>

6. Configure: yaml, properties

yaml of spaces to indent very strict

spring:
  datasource:
    username: root
    password: 123456
    url: jdbc:mysql://localhost:3306/mybatis?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8
    driver-class-name: com.mysql.cj.jdbc.Driver
mybatis:
  type-aliases-package: com.yang.hellospringboot.pojo
  mapper-locations: classpath:com/yang/hellospringboot/mapper/*.xml

properties

spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.url=jdbc:mysql://localhost:3306/mybatis?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

  mybatis.type-aliases-package= com.yang.hellospringboot.pojo
  mybatis.mapper-locations: classpath:com/yang/hellospringboot/mapper/*.xml
Published 87 original articles · won praise 7 · views 5028

Guess you like

Origin blog.csdn.net/y18791050779/article/details/105079570