标签:bin web type body r.java文件 not style control 代码
(在上一节中创建好spring boot以后,就可以开始创建controller了,用于处理web请求)
1. 在spring boot的程序入口所在的 .java文件的同级目录,创建一个 controller.java文件
2. controller中代码如下
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class Controller {
@RequestMapping("/index")
@ResponseBody
public String index() {
return "<h3>this is index page</h3>";
}
}
然后,运行spring boot ,打开 localhost:8080/index
就能看到
这样,一个简单的请求以及返回就完成了。
标签:bin web type body r.java文件 not style control 代码
原文地址:http://www.cnblogs.com/hcy1994/p/7784843.html