今天学习一下SpringBoot的搭建。
1、官网地址
Spring | HomeLevel up your Java code and explore what Spring can do for you.https://spring.io/
第一步在start.spring.io上常见一个web项目,在依赖项搜索web,然后点击generate按钮,下载一个zip包,下载下来解压。(我就是个翻译,没啥技术难度。)
第二步,它让开始码代码
java让人头疼的就是没有IDE基本干不了活,就那引入的东西,不是一般的恶心,关键你还不知道它具体在哪,通过IDE的提醒能好一点,但是在maven没有就绪以前,是没有提示的,这是我不太喜欢这个玩意的一个地方。
package com.lyw.learn;
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 LearnApplication {
public static void main(String[] args) {
SpringApplication.run(LearnApplication.class, args);
}
@GetMapping("/hello")
public String hello(@RequestParam(value = "name", defaultValue = "World") String name){
return String.format("Hello %s", name);
}
}
代码本身比较简单,但是需要的东西可不少。
然后就运行,IDE和cmd都可以的
mvnm spring-boot:run
启动成功,浏览器打开localhost:8080