第一步:新建工程,新建一个父工程。 输入项目名称
点击finish完成父项目的建立,删除src目录,因为这个只是作为父项目而已。
第二步:设置maven的地址
第三步:新建mvc测试的module咯。
点击finish,等jar包完成后,则修改主方法,添加ComponentScan注解, ComponentScan注解后,会去扫描com.springboot.**下的相关spring的bean。 编写一个测试controller
package com.springboot.controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.ArrayList; import java.util.List; @RestController public class UserController { @RequestMapping("/getUser") public List getUser(){ List<String> userList=new ArrayList<String>(); userList.add("zhangsan"); userList.add("lisi"); return userList; } }其实最重要的注解就是 申明@RestController 以及路径映射 @RequestMapping("/getUser")
第四步:启动springboot服务
在浏览器中输入 http://127.0.0.1:8080/getUser,返回下面的结果,则表示mvc请求成功了。
