table of Contents
spring boot Introduction
spring boot history, background online a lot, is a rapid development framework for enterprise-class web projects, the follow-up to fix the difference between the spring and spring MVC
helloworld project structure and presentation
Create a spring boot project in IDEA
IDEA create File -> New -> Project
Version: java: 10.0.2 IDEA: IDEA (Ultimate Edition) 2019.2.3 students registered version
No spring initializer of the need to install plug-in plug-in spring boot
Click next
The reason sprint boot connection is not: being given
Cannot download https://start.spring.io;Status:403
Solution: open phone hot, hot mobile phone connected to the computer
Modify good information
Dependence select spring web
Once created, you can delete some unnecessary files
Hello World example program
The application.properties into application.yml. yml file properties and configuration files that have the same function. Two differences:
- Yml file hierarchy is more clear and intuitive, but note that the format when writing indent alignment. yml configuration file format is more conducive to the expression of the configuration of complex data structures. For example: a list of objects (later chapters will explain in detail).
- Read on properties as good as yml intuitive benefits that do not pay particular attention to writing format indentation aligned.
application.yml file can be modified to open a web page port
server:
port: 8888 # web应用服务端口
Added in pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
Create a controller folder com.xxxx.bootlauch> java> - in src -> mian
create a HelloController
class, enter
@RestController
public class HelloController {
@RequestMapping("/hello")
public String hello(String name) {
return "hello world, " +name;
}
}
After clicking start, you can get in the browser input http://127.0.0.1:8080/hello
Table of Contents Introduction Project Structure
Project directory structure maven generally in accordance with regulatory requirements:
- src / main / resources / static mainly used to store css, images, js and other static files with the development
- src / main / resources / public used to store can be directly used to access html file
- src / main / resources / templates template files used to store web development