1.打开idea ,如图

2 .创建一个spring boot 工程

3.下一步

4. 选择创建项目最初始的项目依赖模块

5.下一步

6.接着在com.lxb.app 新建一个叫做控制器的包 ,包名一般是小写.

6.创建一个Index 的控制器代码如下
package com.lxb.app.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController // @RestController注解相当于@ResponseBody + @Controller合在一起的作用。
public class Index {
@RequestMapping(value = "/hello") //路由/hello 映射 hello的方法 ,返回字符串的hellow world
public Object hello() {
return "hello world";
}
}
从上就创建一个初始化的项目. 点击运行程序后,在浏览器访问 http://localhost:8080/hello ,如图

以上只是记录自己的学习总结,有想学习的可以加个好友一起学习,非专业后端,前端想学的加我.
网友评论