我正在编写一个spring启动应用程序。但我有例外
下面是我的代码"发生内部服务器异常!异常详细信息:方法参数类型String的所需请求参数'caseNumbers'不存在">
我的控制器
public interface ReadCaseByCaseNumberController {
@GetMapping("/case")
ResponseEntity<String> getReadCaseByCaseNumberResponse(@RequestParam String caseNumbers) throws IOException;
}
我ControllerImpl
@RestController
@RequiredArgsConstructor
public class ReadCaseByCaseNumberControllerImpl implements ReadCaseByCaseNumberController {
private final ReadCaseByCaseNumberService readCaseByCaseNumberService;
@Override
public ResponseEntity<String> getReadCaseByCaseNumberResponse(String caseNumbers) throws IOException {
return ResponseEntity.ok(readCaseByCaseNumberService.getReadCaseByCaseNumberResponse(caseNumbers));
}
我的服务
public interface ReadCaseByCaseNumberService {
ReadCaseByCaseNumberResponse getReadCaseByCaseNumberResponse(String caseNumbers) throws IOException;
}
我ServiceImpl
RestController
@RequiredArgsConstructor
public class ReadCaseByCaseNumberControllerImpl implements ReadCaseByCaseNumberController {
@Value("${servce.urlBasePath}")
private String urlBasePath;
@Value("${service.getCaseByCaseNumberPath}")
private String getMessageByCaseNumberURL;
@Override
public String getReadCaseByCaseNumberResponse(String caseNumbers)
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.set("key", "value");
httpHeaders.set("token", "token");
HttpEntity<String> requestEntity = new HttpEntity<>(httpHeaders);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(urlBasePath.concat(getMessageByCaseNumberURL))
.queryParam("caseNumbers", caseNumbers);
ResponseEntity<String> readCaseByCaseNumberResponseResponse =
restTemplate.exchange(builder.build().toUriString(), HttpMethod.GET, requestEntity, String.class);
if (readCaseByCaseNumberResponseResponse.getStatusCode().equals(HttpStatus.OK)) {
return readCaseByCaseNumberResponseResponse.getBody();
} else {
return null;
}
}
}
尝试调试getReadCaseByCaseNumberResponse方法,当你构建UriComponentsBuilder构建器时,它应该生成一个类似于下面的url:yourBaseUrl/?casenumber = someValue