写给新手看的 Spring Boot 入门学习指南( 六 )

(3)启动主程序,打开浏览器访问 http://localhost:8080/hello,就可以看到以下内容,是不是很简单!

HelloWorld

(4)如果我们想传入参数怎么办?

@RestControllerpublicclassHelloWorldController

{ @RequestMapping("/hello")

publicString index(String name)

{

return"Hello World, "+name; }}

重新启动项目,访问 http://localhost:8080/hello?name=neo,返回内容如下:

HelloWorld,neo

经过上一个测试发现,修改 controller 内相关代码,就需要重新启动项目才能生效,这样做很麻烦是不是,别着急。Spring Boot 提供了另外一个组件来解决。

热部署

热启动就需要用到我们在一开始引入的另外一个组件:devtools。它是 Spring Boot 提供的一组开发工具包,其中就包含我们需要的热部署功能。但是在使用这个功能之前还需要再做一些配置。

推荐阅读