SpringBoot project configuration

1, IDEA settings

1. Set zoom

Font size scaling via Ctrl + mouse wheel

2. Automatic prompt setting

3. Automatic prompt for parameter setting method

After setting, the method has parameter prompt

4. Set character set

UTF-8 coding is required

5. Set automatic compilation

6.Maven settings

2, Lombok

1. Function

Previous Java projects were filled with too much unfriendly Code: getter/setter/toString of POJO; Exception handling; The closing operation of I/O flow and so on. These template codes have no technical content and affect the beauty of the code. Lombok came into being.

2. Common notes

@Getter/@Setter: generate getter/setter methods of all member variables on the action class; Act on a member variable to generate the getter/setter method of the member variable. You can set access permissions and lazy loading.
@ToString: acts on a class and overrides the default toString() method. You can limit the display of some fields through the of property and exclude some fields through the exclude property.
@EqualsAndHashCode: acts on the class, overriding the default equals and hashCode
@NoArgsConstructor, @RequiredArgsConstructor, @AllArgsConstructor: acts on a class to generate a constructor. There are staticName, access and other attributes.
@AllArgsConstructor: generate all parameter constructor
@Data: acts on a class and is a collection of the following annotations: @ ToString @EqualsAndHashCode @Getter @Setter @RequiredArgsConstructor

3. Steps

Install plug-ins

Add dependent package

In the pom.xml file, under the dependencies tab, add

<!--support lombok-->

After that, just use the tag in your entity class, so you don't have to write get/set, etc

//Serve as M-layer model in MVC mode: encapsulate data
@Data //lombok automatically provides get set toString hashCode equals
@NoArgsConstructor //Nonparametric structure
@AllArgsConstructor//Fully parametric structure
@Accessors(chain = true) //Chain programming
public class Car{
    //Provide attribute + get/set/toString
    private int id;
    private String name;
    private String type;
    private String color;
    private double price;

3, Hot deployment

1. Function

After each code modification, the server needs to be restarted manually. Can there be an efficient mechanism in the development stage? The program will restart automatically after each code modification

2. Steps

Add dependency
Add dependencies under the dependencies tab

<!--SpringBoot Core mechanism: "Out of the box"
   Just import a specific jar Package files can use the functions directly
   Root cause: SpringBoot It is a simplification of the framework,Internal expansion,No programmer action required.
   <!--Support hot deployment -->

Configure IDEA
Trigger mechanism: after the code of the program is modified, it needs to be restarted, and the state of automatic code compilation trigger modification of IDEA needs to be configured
Key combination: ctrl + shift + alt + / or ctrl + alt + a

Set startup interval
File --> Settings

4, Git

1. Steps

Check whether Git is installed

Install Gitee plug-in
If the plug-in is not installed

Configure Gitee information
The account number is generally email

2. Simple use

Update project

Click OK directly

Submit and upload

5, Other settings

1. Set up a series of operations such as database connection and port

src --> main --> resources
Create xxx.yml
Right click -- > New

  port: 8091   #Set port
    context-path: /
  datasource:       #Set database information
    driver-class-name: com.mysql.cj.jdbc.Driver  #Driver
    url: jdbc:mysql://localhost:3306/jt?useUnicode=true&useSSL=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai&autoReconnect=true&allowMultiQueries=true
    username: root                          #The user defaults to root
    password: dmm19920806                   #The password defaults to root

#Mybatis plug configuration
  type-aliases-package: com.jt.pojo              #Entity class package
  mapper-locations: classpath:/mappers/*.xml     #Automatically load the xxxMapper.xml file
    map-underscore-to-camel-case: true           #Turn on hump rules

    com.jt.mapper: debug                         #Run display SQL statement

2. Write startup class

SRC -- > main -- > your package -- > startup class

@MapperScan("com.jt.mapper")  //Scan Mapper package
public class SpringBootRun {

    public static void main(String[] args) {

        SpringApplication.run(SpringBootRun.class, args);

3. Write test class

SRC -- > test -- > java -- > create package -- > test class

Be sure to add @ SpringBootTest annotation

test method
public + void + method name ()
Must be in this format and have no parameters

Keywords: Java Spring Boot

Added by Tensing on Sun, 05 Sep 2021 08:32:49 +0300