如何在Spring控制器的@Getmapping之后定义一个类或方法



当在Spring Controller中定义@Getmapping注释后的类时,除了Iterable之外,还有其他方法吗?请参阅下面的代码示例,了解如何在Spring Controller中定义@Getmapping之后的类或方法,

@RestController
@RequestMapping("/rooms")
public class RoomController {
@Autowired
private RoomRepository roomRepository;
@GetMapping
public Iterable<Room> getRooms(){
return this.roomRepository.findAll();
}
}

是否有其他方法在Spring Controller的@Getmapping之后定义一个类或方法

基于HTTP GET规范:

GET方法表示检索任何信息(以数据的形式)实体)由Request-URI标识。如果请求uri引用对于数据产生过程,所产生的数据应当是作为响应中的实体返回,而不是对象的源文本进程,除非该文本恰好是该进程的输出。

因此,对于GetMapping,您可以返回任何定义为entity的类型(即任何适合您要求的类)。

最新更新