Spring @Controllerと@RestControllerアノテーションの違い 質問する

Spring @Controllerと@RestControllerアノテーションの違い 質問する

@Controllerスプリングとアノテーションの違い@RestController

@Controllerアノテーションは Web MVC アプリケーションと REST アプリケーションの両方に使用できますか?
使用できる場合、Web MVC アプリケーションか REST アプリケーションかをどのように区別できますか。

ベストアンサー1

  • @Controllerクラスを Spring MVC コントローラーとしてマークするために使用されます。
  • @RestController@Controllerは、および注釈を追加するだけの便利な注釈です@ResponseBody(参照:Javadoc

したがって、次の2つのコントローラ定義は同じことを行う必要があります

@Controller
@ResponseBody
public class MyController { }

@RestController
public class MyRestController { }

おすすめ記事