如何处理“原始类型使用”在从控制器中发送原始响应性时警告?

发布于 2025-02-05 16:20:05 字数 1117 浏览 2 评论 0原文

我有一个简单的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏天碎花小短裙 2025-02-12 16:20:05

可以在方法签名返回类型上替换wendersentity&lt;?

public ResponseEntity<?> submitAction(@RequestBody WorkflowActionDto workflowActionDto)

您 通用类型,因此wendersentity&lt;?&gt;wendersentity是相同的。

编辑:

当我看到您返回wendersentity.ok(httpstatus.ok),因此您正在返回类型httpstatus的字体。因此,您可以使用Repententity&lt; httpstatus&gt;在methode签名中更加明确。

You can replace ResponseEntity<?> instead of ResponseEntity on your method signature return type:

public ResponseEntity<?> submitAction(@RequestBody WorkflowActionDto workflowActionDto)

You can avoid IDE warnings, but they are actually the same, compiler would replace it with generic type, so ResponseEntity<?> and ResponseEntity are the same.

EDIT:

As I see you are returning ResponseEntity.ok(HttpStatus.OK), so you are returning a body of type HttpStatus. So you can be more explicit in your methode signature by using ReponseEntity<HttpStatus>.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文