Skip to content

Instantly share code, notes, and snippets.

@odrotbohm
Created October 13, 2016 16:02
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 odrotbohm/918da1a29d686d49a617973201311233 to your computer and use it in GitHub Desktop.
Save odrotbohm/918da1a29d686d49a617973201311233 to your computer and use it in GitHub Desktop.
<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