io.micronaut.starter.feature.view.reactControllerJava.rocker.raw Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of micronaut-starter-core Show documentation
Show all versions of micronaut-starter-core Show documentation
Generates Micronaut applications
@import io.micronaut.starter.application.Project
@args (
Project project
)
@if (project.getPackageName() != null) {
package @project.getPackageName();
}
import io.micronaut.core.annotation.Introspected;
import io.micronaut.http.annotation.Controller;
import io.micronaut.http.annotation.Get;
import io.micronaut.http.HttpResponse;
import io.micronaut.serde.annotation.Serdeable;
import io.micronaut.views.View;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
@@Controller
public class AppController {
@@Serdeable.Serializable
public record CurrentTime(String now) {}
@@Introspected
public record InitialProps(String name) {
}
@@View("App")
@@Get
public HttpResponse index() {
return HttpResponse.ok(new InitialProps("'your name goes here'"));
}
@@Get("/api/time")
public CurrentTime time() {
return new CurrentTime(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).format(LocalDateTime.now()));
}
}