Last active
June 21, 2019 22:26
-
-
Save ShelbyCohen/1e5e0ccdc0ab7245f105c75102313bf8 to your computer and use it in GitHub Desktop.
Kotlin Example of Class and Controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class Greeting(val id: Long, val content: String) | |
Next, a GreetingController will be used for a get request: | |
@RestController | |
class GreetingController { | |
val counter = AtomicLong() | |
@GetMapping("/greeting") | |
fun greeting(@RequestParam(value = "name", defaultValue = "World") name: String) = | |
Greeting(counter.incrementAndGet(), "Hello, $name") | |
} | |
When creating the Application class Spring Boot looks for a public static main method. This can be defined in Kotlin using a top-level function defined outside Application class like this: | |
@SpringBootApplication | |
class Application | |
fun main(args: Array<String>) { | |
SpringApplication.run(Application::class.java, *args) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment