springboot项目测试接口方法
在springboot项目中,写完接口如果不和前端联动,怎么样才能走到后台接口呢这是我的controller层后面的层级就不一一展示了,比较简单。@RestControllerpublic class TestController {@AutowiredTestService testService;@GetMapping("/")public ModelAndView hello(){List&
·
在springboot项目中,写完接口如果不和前端联动,怎么样才能走到后台接口呢,可以使用postman软件,如果你想简单测试,按我的以下步骤就行
1.这是我的controller层后面的层级就不一一展示了,比较简单。
@RestController
public class TestController {
@Autowired
TestService testService;
@GetMapping("/") //这个地方你也可以写你自己定义的路径,访问的时候换成你的路径就行
public ModelAndView hello(){
//去数据库查询你的数据
List<PsRotation> map = testService.selectList();
//index必须和你的页面名字一致
return new ModelAndView("index");
}
}
2.index页面里面可以随便放点东西就行,下面是我的页面和页面位置,这个就是对应的controller的 return new ModelAndView("index");
3.运行项目
4.查看你项目的端口
5.浏览器访问http://localhost:8081/
然后我数据库就是两条数据,然后我的接口就是对的,可以走通。
更多推荐
已为社区贡献4条内容
所有评论(0)