1.官网下载Spring Boot项目 start.spring.io/ 2.更新maven,下载必须的依赖 问题:发现pom报错,parent那里有问题。 解决:关掉代理,maven重新update,正常下载jar。 3.java run启动DemoApplication报错
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
复制代码
报错:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Wed Feb 27 17:56:02 CST 2019
There was an unexpected error (type=Not Found, status=404).
No message available
复制代码
解决:
添加依赖如下
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
复制代码
第一种:新建controller
package com.example.demo;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class TestController {
@RequestMapping("getName/{name}")
@ResponseBody
public String getName(@PathVariable String name){
if(name==null){
name="null";
}
return "hello miky"+name;
}
}
复制代码
浏览器输入:http://localhost:8080/getName/haha 显示如下:
hello mikyhaha
第二种:添加资源,如html页面。 在resources下新建static包,然后浏览器输入地址:http://localhost:8080/index.html
)