Spring环境搭建

1.下载并安装jdk:https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html

2.下载并安装maven:http://maven.apache.org/download.cgi

3.Maven换源conf/setting.xml:

<mirrors>
    <mirror>
        <id>alimaven</id>
        <mirrorOf>central</mirrorOf>
        <name>aliyun maven</name>
        <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
    </mirror>
</mirrors>

4.创建demo项目(添加Spring Web依赖):https://start.spring.io/

5.编辑文件src/main/java/com/example/demo/DemoApplication.java:

package com.example.demo;

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

@SpringBootApplication
@RestController
public class DemoApplication {
    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
    
    @GetMapping("/hello")
    public String hello(@RequestParam(value = "name", defaultValue = "World") String name) {
        return String.format("Hello %s!", name);
    }
}

6.启动项目:

mvn spring-boot:run

7.浏览器访问:http://localhost:8080/hello

posted @ 2020-06-22 17:27  viewts  阅读(239)  评论(0编辑  收藏  举报