Springboot-mybtis framework construction notes

Springboot-mybtis framework construction notes

1. Dependence

Enter the spring official website to copy dependencies (remove the novice case)
link: link
Enter the official website to copy dependencies

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>demo-project1</artifactId>
    <version>1.0-SNAPSHOT</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    <pluginRepositories>
        <pluginRepository>
            <id>alimaven spring plugin</id>
            <name>alimaven spring plugin</name>
            <url>https://maven.aliyun.com/repository/spring-plugin</url>
        </pluginRepository>
    </pluginRepositories>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.2.2.RELEASE</version>
            </plugin>
        </plugins>
    </build>

</project>

2. Establish a local maven warehouse and modify the central warehouse to the Ali mirroring path

1. Unzip the maven file to this path

C:\my_java\apache-maven-3.5.2

2. Configure maven environment variables

MAVEM_HOME
Insert picture description here

3. Find the maven configuration file and modify it

maven configuration file
You can open it with Super Notepad, I open it with idea,
find the mirrors, and paste the code
Modify the configuration file mirror address

 <mirror>
      <id>nexus-aliyun</id>
      <mirrorOf>*</mirrorOf>
      <name>Nexus aliyun</name>
      <url>https://maven.aliyun.com/nexus/content/groups/public</url>
    </mirror>

Of course, after modifying the maven configuration file, remember to add dependencies to the project (the complete dependencies posted at the top have already been added)

<pluginRepositories>
        <pluginRepository>
            <id>alimaven spring plugin</id>
            <name>alimaven spring plugin</name>
            <url>https://maven.aliyun.com/repository/spring-plugin</url>
        </pluginRepository>
    </pluginRepositories>

Finally, don’t forget to set the maven path in idea
Insert picture description here

Three, create the first demo

Project directory structure
Project structure
code

package net.xdclass.demoproject;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication//启动程序
//@ComponentScan({"net.xdclass.controller","net.xdclass.package2"})//扫描器
public class DemoProjectApplication {
    
    

    public static void main(String[] args) {
    
    

        SpringApplication.run(DemoProjectApplication.class, args);
    }

}

package net.xdclass.demoproject.controller;


import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 视频控制器
 */

//@Controller
@RestController
@RequestMapping("/api/v1/video")
public class VideoController {
    
    
    @RequestMapping("list")
    //@GetMapping("list")
    //@PostMapping("list")
    //@ResponseBody
    public Object list(){
    
    

        Map<String,String > map = new HashMap<>();
        map.put("1","面试专题课程");
        map.put("2","SpringCloud微服务课程");

        return map;

    }
}

Configuration file: configure the allowed access range, here are the three folders under open recources

spring.resources.static-locations = classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,classpath:/templates/

Enter the address in the browser to access the corresponding resources

http://localhost:8080/test.jpeg

Input the corresponding splicing address of the interface to access the content (or use the interface test tool)

http://localhost:8080/api/v1/video/list

Modify service port

server.port=端口号

Note that if the startup type Aplication has not been specially set, it should be placed in the root directory. It is better to not read the
Insert picture description here
package in the idea: enter the project root directory in the temina and enter

mvn install

Run the jar package: (close idea, project stop)

java -jar 包名

Add the daemon to run the jar package: (only for Linux or Apple systems)

nuhup java  -jar 包名 & 

Skip test project creation

mvn install -Dmaven.test.skip=true

Packaged project directory (java package directory)
Insert picture description here
Unzip in linux system

unzip 包名

For other details, please refer to
1
2

Guess you like

Origin blog.csdn.net/qq_39219307/article/details/103594954