Create a gist now

Instantly share code, notes, and snippets.

<body>
<div th:text="${viewModel.yourDescriptiveMethod()}">placeholder</div>
</body>
@RequiredArgsConstructor
public class ViewModel {
private final @NonNull YourService service;
public boolean yourDescriptiveMethod() {
return service.someMethod()
}
// … more methods
}
@Controller
@RequiredArgsConstructor
class YourController {
private final YourService service;
// Available in all views rendered by that controller
@ModelAttribute
public ViewModel viewModel() {
return new ViewModel(service);
}
// … request mappings
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment