(1) Create a project, use spring boot, and configure maven.
The following is to choose some dependent JAR packages. If you develop a web project, the web package must be imported. Others, such as databases or templates, depend on individual circumstances. If you just want to play a demo and don't involve database development, then don't import dependencies such as Mybatis, otherwise it will prompt you to configure the database information before running.
The following is the simple code of our project, which is to get a controller, which is equipped with a function to map the path.
(2) The following is the configuration of hot deployment. Hot deployment means that after you modify some code, save it, you can directly refresh the browser to see the effect, you no longer need to restart the server to re-run, although we re-run a button for a few seconds, but the project is big Not just seconds. There are mainly 4 places that need to be configured.
- Add SDK dependencies in POM.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
- add maven startup plugin
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
--idea also needs to be set to be able to be automatically compiled in pairs. Ctrl+Shift+A, search build project automatically
, enter the setting interface, you can open the setting interface by yourself without searching, and then find the corresponding option. Check it.
——Continue the shortcut key search Registry
, open the interface, and find the following option, which literally means the setting that allows the program to be automatically compiled at runtime. Check it.
Then, it worked.
(3) The use of the database. used here MySQL
. First, configure the dependent jar
packages and add the following. If there are no special requirements, maven repository
find the version with the most users in it:
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.39</version>
</dependency>
Then it is to configure the data source. Here the official website gives it by default application.properties
, but the writing and prompting are not very friendly. spring boot
People prefer to use application.yml
it in it. As you can see, just change the suffix of the original file, and then we are in This file writes the configuration of the data source:
spring:
datasource:
url: jdbc:mysql://127.0.0.1:3306/xxx
username: xxx
password: xxx
driver-class-name: com.mysql.jdbc.Driver
That's it.