Skip to content

Instantly share code, notes, and snippets.

@zenon
Created February 12, 2018 13:34
Show Gist options
  • Save zenon/d6a6c542a2095d488ab75642aed78079 to your computer and use it in GitHub Desktop.
Save zenon/d6a6c542a2095d488ab75642aed78079 to your computer and use it in GitHub Desktop.
Some sniplets for Thymeleaf
RESTful: /mymock/17
Model:
======
package com.….;
import lombok.Data;
@Data
public class MockModel {
String id;
}
Controller:
===========
package com.….;
@Controller
@RequestMapping("/surveyMock/{id}")
public class SurveyMock {
@GetMapping()
String surveyMock(Model model, @PathVariable("id") String id) {
MockModel mm = new MockModel();
mm.setId(id);
model.addAttribute("attributes", mm);
return "surveyMock";
}
HTML:
=====
<span th:text="${attributes.id}">X</span>
Iterator, e.g. lists:
=====================
<div th:each="elem : ${attributes.stuff}">
<span th:text="${elem}">XYZXYZXYZ</span>
<span th:text="${elem.length()}">XYZXYZXYZ</span>
</div>
Links:
======
<link rel="stylesheet" href="styles.css" th:href="@{/styles.css}"></link>
HTTP Post mapping (Controller):
===============================
@PostMapping()
public String mock(@ModelAttribute(name = "attributes") @Valid MockModel fields,
BindingResult bindingResult,
@PathVariable("id") String id) {
if (bindungResult.hasErrors()) {
LOGGER.error("Number of bind errors: ", bindungResult.getErrorCount());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment