一、利用Spring boot在网页中输出Helloworld
1.新建一个项目
2.选择java8
3.选择web和Spring web
4.给项目命名
项目创建完毕后还需要等待下载资源
5.创建一个网页
在com.example.demo目录下新建一个package,然后在新的package中新建一个Java类
Helloworld类代码如下
package com.example.demo.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class HelloWorld {
@ResponseBody
@RequestMapping("/hello")//用于访问网页的,后面用到的http://localhost:8080/hello中的hello来源
public String hello(){//网页内容
return "Hello World!";
}
}
6.启动项目
在DemoApplication类中右击后运行
出现这个就意味着运行成功
打开浏览器输入http://localhost:8080/hello即可看到如下效果