Skip to content

Instantly share code, notes, and snippets.

@ShelbyCohen
Last active June 21, 2019 22:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShelbyCohen/1e5e0ccdc0ab7245f105c75102313bf8 to your computer and use it in GitHub Desktop.
Save ShelbyCohen/1e5e0ccdc0ab7245f105c75102313bf8 to your computer and use it in GitHub Desktop.
Kotlin Example of Class and Controller
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