Background: I have been worrying about a problem, that is, the mobile phone is installed with several music apps: system, netease Cloud, QQ music… Some favorite songs can be listened to on this App, but not on another App. If you want to listen to other songs, you have to switch App, which is very troublesome, so you want to download these songs, and then upload them to your own music App (only for their own use, not infringement), it feels very good. Here first use Springboot to develop a music website try.

Main Contents of this article

Development tool: Jetbrain Idea

Development language: Java

Development platform: Windows

Desired goal: Manually build a Springboot project and run it successfully.

Develop detailed steps

Create an empty folder and name it Xiaoming music

2, use Idea to open this directory, will automatically generate some files, do not need to ignore

Create three files in the root directory

  1. .gitignoreIgnore files for code versioning
.DS_Store node_modules /dist target/ logs/ uploadFiles/ # IntelliJ IDEA Project files .idea *.iws *.iml *.ipr .mvn mvnw*  # Editor directories and files .vscode *.suo *.ntvs* *.njsproj *.sln *.sw*Copy the code
  1. pom.xmlThe Maven project configuration file

      
<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>cc.xiaoming</groupId>
    <artifactId>xiaoming-music</artifactId>
    <packaging>pom</packaging>
    <version>1.0.0</version>

    <! -- SpringBoot Project parent dependencies -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.2</version>
        <relativePath/>
    </parent>

    <! -- attribute parameters -->
    <properties>
        <java.version>1.8</java.version>
    </properties>

    <! -- Various dependency frameworks -->
    <dependencies>
        <! -- Project dependencies for SpringBoot Web -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

</project>
Copy the code
  1. readme.mdDescription file of the project
Xiao Ming's personal music website
Copy the code

Right-click the pom. XML file and select Add as Maven Project

Convert this directory into a Maven project, and you will notice that the pom.xml icon has changed, indicating that the transformation has been successful. At this point, we will create the SpringBoot launcher.

I’m using JDK 8. If you’re using JDK 8, you need to change it manually.

5. Add module: Springboot boot program

Right-click the project name and create new -> Module -> Maven -> SDK 1.8. Do not select next.

Finally, enter the module name, finish.

At this point, you will notice that there is an extra folder in the project root directory, which is the module we added.

XML is the parent project, and the new module is the child project. The child project is added to the parent project in this way.

<groupId>cc.xiaoming</groupId>
<artifactId>xiaoming-music</artifactId>
<packaging>pom</packaging>
<version>1.0.0</version>
<modules>
    <module>xiaoming-starter</module>
</modules>
Copy the code

The parent project information is also added to the child project’s POM.xml.

<parent>
    <artifactId>xiaoming-music</artifactId>
    <groupId>cc.xiaoming</groupId>
    <version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>xiaoming-starter</artifactId>
Copy the code

Add a startup class: XmMusicApplication

In the subproject xiaoming-starter/ SRC /main/ Java directory, add cc.xiaoming, and add xmmusicApplication.java to the root directory of the package.

package cc.xiaoming;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/** * SpringBoot program boot class */
@SpringBootApplication
@RestController
public class XmMusicApplication {

    public static void main(String[] args) {
        SpringApplication.run(XmMusicApplication.class, args);
    }

    @RequestMapping("/hello")
    public String hello(a) {
        return "Hello, Welcome to XmMusic Web."; }}Copy the code

7. Run the program

Before running, import the dependency packages.

Run the launch class and enter the access address in the browser address bar.

Run successfully, this Springboot project is basically set up, we can continue to add the functionality we need.