end0tknr's kipple - web写経開発

太宰府天満宮の狛犬って、妙にカワイイ

SpringBoot for java における app root (path)の routing

メモ。

以下のように書くと、 /hello/world な 2段? endpoint でroutingできます。

package com.coltware.spring.sample.api;

import com.coltware.spring.sample.model.WorldModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/hello")
public class HelloController {

    private static final Logger log
    = LoggerFactory.getLogger(HelloController.class);

    @Autowired
    WorldModel model;

    @GetMapping(value = "/world")
    public WorldModel world(){
        return model;
    }

}