SpringBoot-- classic Hello World [two]

Foreword

To create a hello world chant

step

Of course, it is to open our IDEA to create a Maven project Kazakhstan

Create a project

1. File->New->Project

2.Maven-> JDK version choose -> Next

3. Groupld->Artifactld->Next

4. location->Finsh

5. Open Auto Import

Import dependence

Import-related dependence of SpringBoot into SpringBoot official website clicks Quick startin the Spring Lnitializr
after fill in specific information, we can click on Explore- Ctrl + Spaceto generate a pom.xmlfile, simply copy the configuration to cover the project.
Generate pom configuration
Generate pom configuration
Covering pom configuration

Main program

Write a main program used to start SpringBoot applications, please pay attention to self-created position.
1. Create a class file
create

2. mark the main program
Mark application is SpringBoot

3. The main program code as follows

package com.wangyang;


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

/**
 * @SpringBootApplication 标注一个主程序类,说明这是一个Spring Boot应用
 */
//DataSourceAutoConfiguration禁止自动加载,不然会产生报错
@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})
public class HelloWorldMainApplication {

    public static void main(String[] args) {
        //启动Spring应用
        SpringApplication.run(HelloWorldMainApplication.class,args);
    }
}

Write business code

1. Create a controller controller

2. Business Code

package com.wangyang.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class HelloWorldController {

    @ResponseBody
    @RequestMapping("/")
    public String hello(){
        return "hello world";
    }
}

Run the main method

Returns to the main program, the main method can be run directly
start up
start up

address

access

Project Package

Run jar package

access

Guess you like

Origin www.cnblogs.com/wangyang0210/p/11809750.html