Commit 2a5400c4 authored by Michael's avatar Michael

added simple rest controller

parent 17329e95
......@@ -38,4 +38,5 @@ Clone or download thist repository and change into this folder.
- [spring.io getting started](https://spring.io/guides/gs/spring-boot/)
- [spring.io external config](https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html)
- [spring.io endpoint security](https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-monitoring.html)
- [spring.io spring application properties](https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html)
\ No newline at end of file
- [spring.io spring application properties](https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html)
- [spring.io REST service](http://spring.io/guides/gs/rest-service/)
\ No newline at end of file
......@@ -3,9 +3,9 @@
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework</groupId>
<groupId>net.rootknecht</groupId>
<artifactId>spring-demo</artifactId>
<version>0.1.0</version>
<version>0.2.0</version>
<packaging>jar</packaging>
<name>Spring Boot Docker</name>
<description>Minimal Spring Boot Variable Injection Demo</description>
......
package demo;
import java.util.concurrent.atomic.AtomicLong;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
......@@ -21,12 +23,19 @@ public class Application {
@Autowired
private Properties properties;
private static final String template = "Hello, %s!";
private final AtomicLong counter = new AtomicLong();
@RequestMapping("/")
public String home() {
return "Hello " + foo + "<br>---<br>" + yamlProperties + "<br>---<br>" + properties;
}
@RequestMapping("/content")
public Content greeting(@RequestParam(value="name", defaultValue="World") String name) {
return new Content(counter.incrementAndGet(), String.format(template, name));
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
......
package demo;
import lombok.Data;
import lombok.ToString;
@Data
@ToString(includeFieldNames = false)
public class Content {
private final long id;
private final String content;
public Content(long id, String content) {
this.id = id;
this.content = content;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment