Springboot
1. Introduction to Springboot
1.1 Introduction: Springboot is a framework to simplify Spring application development. Conventions are greater than configurations. |
1.2 Advantages: You can quickly build Spring projects that run independently; There is a Servlet container in the framework, so there is no need to rely on external sources, so there is no need to implement a war package (it comes with Tomcat, no need to deploy, and is highly integrated with Servlet); Try our best to remove repetitive and disgusting xml configuration (optimize xml and streamline it) |
1.3 Directory structure: under the resource directory static : save all static resources js, css, images; templates : save all template pages (jsp is not supported by default); application.properties : Configuration file of SpringBoot application |
2.springboot project
2.1 Create https://start.spring.io http://start.spring.io http://start.springboot.io/ (最优) https//start.aliyun.com |
2.2 Testing @RestController =@Controller+@ResponseBody |
2.3 Change port number: 2.4 Test method 2 (simulating operations on a virtual machine) package test and access After opening, enter cmd in the current directory After startup is complete, test on the web page: |
2.5 yml basic syntax: (1) Modify into yml file, hierarchical directory, more clear Note: The space in the middle cannot be omitted, otherwise the configuration will be invalid. |
3. Actual combat
(1) Create a project and check MySQL and mybatis |
3.2 Modify the version number and change the application file suffix yml |
3.3 Introduce MySQL database related configuration: modify the MySQL version serverTimezone=Asia/Shanghai |
3.4 Introducing mybatis related configuration: fuzzy matching |
3.5 Create tables, packages, and entity classes. . . . . . Create mapper interface, interface implementation class, etc. Add annotation to mapper interface: @Mapper Service and its implementation classes |
3.6 Extension: The second way to write the mapper interface (no need to write it repeatedly in xml) Add @RequestBody to the parameters in the Controller method (usually this annotation is added to the object type, and json format data is subsequently passed) Transfer json format data from postman |
3.7 extension can change the annotations in the mapper interface to the Application.java file |