junit java.lang.IllegalArgumentException:没有足够的变量值可用于扩展“id”错误

cgvd09ve  于 2023-11-19  发布在  Java
关注(0)|答案(1)|浏览(139)
@RequestMapping(value= "/project/{id}", method= RequestMethod.GET)
        public Project getEmployeeById(@PathVariable int projectId) throws Exception {

     Optional<Project> emp =  projectservice.getProjectById(projectId);

            if(!emp.isPresent())
                throw new Exception("Could not find employee with id- " + projectId);

            return emp.get();
        }

字符串
本试验方法的适用范围为:

@Test
    public void getEmployeeByIdtest() throws Exception {

        MockHttpServletResponse response = mvc.perform(get(restEndPoints.GET_EMPLOYEE_ID.uri())
                .param("projectId", "2")).andReturn().getResponse();
        assertThat(response.getStatus()).isEqualTo(HttpStatus.OK.value());
        assertNotNull(response.getContentAsString());
    }


获取错误:
java.lang.IllegalArgumentException:无法使用足够的变量值来展开“id”

cunj1qz1

cunj1qz11#

而不是

@RequestMapping(value= "/project/{id}"

字符串
你应该使用

@RequestMapping(value= "/project/{projectId}"


curlies中的名称必须与方法参数名称匹配。

相关问题