Skip to content

Instantly share code, notes, and snippets.

@ko-sasaki
Created June 14, 2025 05:46
Show Gist options
  • Save ko-sasaki/f38dfe9fc7146268520cf72f333565e5 to your computer and use it in GitHub Desktop.
Save ko-sasaki/f38dfe9fc7146268520cf72f333565e5 to your computer and use it in GitHub Desktop.
server:
port: 8081
sample:
message: Hello, Application Yaml!
///usr/bin/env jbang "$0" "$@" ; exit $?
package api;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
//DEPS org.springframework.boot:spring-boot-starter-web:3.5.0
//FILES application.yml
//REPOS central,jitpack,google
@SpringBootApplication
@RestController
public class SpringBootSample {
@Value("${sample.message}")
private String message;
public static void main(String[] args) {
SpringApplication.run(SpringBootSample.class, args);
}
/**
* 固定メッセージを返却する.
*/
@GetMapping("/hello")
public String hello() {
return "Hello, World!";
}
/**
* URLパスで指定された文字列でメッセージを置換して返却する.
*/
@GetMapping("/hello/{name}")
public String hello(@PathVariable String name) {
return "Hello, {name}!".replace("{name}", name);
}
/**
* application.ymlのメッセージを表示する
*/
@GetMapping("/hello/message")
public String message() {
return message;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment