【问题标题】:@RestController over interface + spring@RestController over interface + spring
【发布时间】:2021-06-05 12:15:06
【问题描述】:

我偶然发现了这种使用 RestController 注解的技术。 (我不是在互联网上看到的,而是在我看到的一个例子中看到的。我在互联网上找不到它)

@RestController
@RequestMapping("api/user/point")
public interface ExampleRestController {


    @PostMapping("{key}" )
    @Operation(summary = "Manage...", 
            description = "Allow user ...")
    public HttpStatus changePoints(
            @PathVariable 
            @NotBlank 
            @Parameter(description = "Id user") String key,
            @RequestParam("point") 
            @Min(0) @Parameter(description = "count something..", required = true) Long point,
            @RequestParam("type") 
            @Parameter(description = "Type of...", required = true) TypeOperation type

    );
}

这是什么技术,谁知道?

我见过这样的 Rest Api。 Spring 是否也可以像在执行 ...extend CrudRepository 时那样在 RestController 中动态创建端点方法?在这种情况下 AOP 是如何工作的?毕竟,为了配置bean,我们需要把注解放在类上面(就像在服务层是怎么做的一样),如果放在接口上面,bean的全自动配置就不行了保证

【问题讨论】:

  • 以下是一个很好的起点:Spring Reference Documentation
  • 请仔细阅读问题。我没有问你怎么做,我知道文档在哪里,我也没有问你怎么做,请阅读问题......
  • @skhyho 我不是反对者。我重新阅读了您的问题,但仍然认为我的第一条评论是有效的。您的问题不是针对某个主题的。可能您需要将问题分解为您面临的特定问题或您无法理解的概念。

标签: spring-boot java-11


【解决方案1】:

它是spring-interface-driven-controllers。 这是 Spring MVC 的新特性。 (从 Spring 5.1 开始)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-03
    • 2015-10-28
    • 2015-07-30
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    • 2016-06-28
    • 1970-01-01
    相关资源
    最近更新 更多