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