我想为我的控制器编写一个测试。我需要向 get() 传递一个参数。我该怎么做?控制器:@GetMapping("/getClientById")    public ModelAndView getClientById(Integer id){        return new ModelAndView("getClientById", "client", clientService.getClientById(id));    }测试方法:given().header("Content-Type", "application/x-www-form-urlencoded")                .when()                .get("getClientById/")//How can I put here an ID ?                .then()                .statusCode(200);
                    
                    
                1 回答
                            慕斯709654
                            
                                
                            
                        
                        
                                                
                    TA贡献1840条经验 获得超5个赞
您必须在映射中包含参数
@GetMapping("/getClientById/:clientId")
    public ModelAndView getClientById(@PathParam("clientId") Integer id){或者
@GetMapping("/getClientById")
    public ModelAndView getClientById(@QueryParam("id") Integer id){然后分别
.get("getClientById/youridvalue")//How can I put here an ID ?和
.get("getClientById?id=youridvalue")//How can I put here an ID ?至于第二个选项,我认为有一种方法可以包含查询参数,但我不知道您使用的是什么 API,因此无法详细说明(可能还没有)
添加回答
举报
0/150
	提交
		取消
	