如何处理“原始类型使用”在从控制器中发送原始响应性时警告?
我有一个简单的API,可以对记录发起一些动作并返回200响应:
/**
* Initiate some workflow.
*
* @param recordsBulkInitiate records to initiate
* @return {@link ResponseEntity}
*/
@ApiOperation(value = "initiate workflow")
@PostMapping("/initiate")
public ResponseEntity bulkInitiateRecords(@RequestBody InitiateBulkRecordsDto recordsBulkInitiate) {
workflowService.bulkInitiate(recordsBulkInitiate);
return ResponseEntity.ok(OK);
}
/**
* Submit some workflow action on arecord
*
* @param workflowActionDto the record action data
* @return {@link ResponseEntity}
*/
@ApiOperation(value = "action taken by user")
@PostMapping("/action")
public ResponseEntity submitAction(@RequestBody WorkflowActionDto workflowActionDto) {
log.info("submit action on record [{}]", workflowActionDto);
workflowService.submitRecordAction(workflowActionDto);
return ResponseEntity.ok(OK);
}
Sonarlint和Intellij都会发出警告:“不应使用原始类型”。
我应该如何处理此警告?目前,我只是使用响应态度< object>
,它似乎是一个黑客。
I have a simple APIs that initiates some action on records and return a 200 response:
/**
* Initiate some workflow.
*
* @param recordsBulkInitiate records to initiate
* @return {@link ResponseEntity}
*/
@ApiOperation(value = "initiate workflow")
@PostMapping("/initiate")
public ResponseEntity bulkInitiateRecords(@RequestBody InitiateBulkRecordsDto recordsBulkInitiate) {
workflowService.bulkInitiate(recordsBulkInitiate);
return ResponseEntity.ok(OK);
}
/**
* Submit some workflow action on arecord
*
* @param workflowActionDto the record action data
* @return {@link ResponseEntity}
*/
@ApiOperation(value = "action taken by user")
@PostMapping("/action")
public ResponseEntity submitAction(@RequestBody WorkflowActionDto workflowActionDto) {
log.info("submit action on record [{}]", workflowActionDto);
workflowService.submitRecordAction(workflowActionDto);
return ResponseEntity.ok(OK);
}
Both Sonarlint and intellij throws warnings: "Raw types should not be used".
How should I handle this warning? For now, I'm just using ResponseEntity<Object>
which seems like a hack.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以在方法签名返回类型上替换
wendersentity&lt;?
您 通用类型,因此
wendersentity&lt;?&gt;
和wendersentity
是相同的。编辑:
当我看到您返回
wendersentity.ok(httpstatus.ok)
,因此您正在返回类型httpstatus
的字体。因此,您可以使用Repententity&lt; httpstatus&gt;
在methode签名中更加明确。You can replace
ResponseEntity<?>
instead ofResponseEntity
on your method signature return type:You can avoid IDE warnings, but they are actually the same, compiler would replace it with generic type, so
ResponseEntity<?>
andResponseEntity
are the same.EDIT:
As I see you are returning
ResponseEntity.ok(HttpStatus.OK)
, so you are returning a body of typeHttpStatus
. So you can be more explicit in your methode signature by usingReponseEntity<HttpStatus>
.