以下の内容はhttps://tech.excite.co.jp/entry/2022/05/20/164341より取得しました。


Controllerでもinterfaceをimplementsすることができる

こんばんは。エキサイト株式会社の中尾です。

あまり需要がないかもしれないですが、Controllerでもinterfaceをimplementsすることができます。

ただ普通にimplementsすることは、どんなクラスでもできますが、@RequestMapping@GetMapping()@RequestParam()も使えます。

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@RequestMapping("hello")
public interface HelloController {
    /**
     * helloを返すエンドポイント
     *
     * @param hello
     * @return
     */
    @GetMapping()
    String hello(@RequestParam(name = "hello") String hello);
}
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloControllerImpl implements HelloController {
    @Override
    public String hello(String hello) {
        return hello + "\n";
    }
}

気をつけて欲しいのは@RestControllerは実装クラスにつけるということです。

まぁ、swaggerでも良いのですが




以上の内容はhttps://tech.excite.co.jp/entry/2022/05/20/164341より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14