With the Spring Tool Suite to create a project, page templates with thymeleaf,
Java tacos. Web. DesignTacoController.
package tacos. Web;
The import... ;//omission is not important code
The import tacos. Taco;
The import tacos. Ingredient;
The import tacos. Ingredient. Type;
@ Slf4j
@ Controller
@ RequestMapping ("/design ")
Public class DesignTacoController {
@ GetMapping
Public String showDesignForm Model (Model) {
ListIngredients=Arrays. AsList (
New Ingredient (" FLTO ", "Flour Tortilla", the WRAP)...//omission is not important code
);
Type [] types=Ingredient. The Type. The values ();
For (Type, Type: types) {
Model. The addAttribute (type. The toString () toLowerCase (), filterByType (ingredients, type));
}
Model. The addAttribute (" design ", the new Taco ());//here in the model into called design Taco Bean
Return "design";
}
@ PostMapping
Public String processDesign (@ Valid Taco design, Errors Errors) {//here seems to be caused by the error, will @ Valid after remove, is not an error
{if (errors. HasErrors ())
Return "design";
}
The info (" Processing design: "+ design);
The return of "redirect:/orders/current";
}
Private ListFilterByType (List Ingredients, Type, Type) {... }//omit important code
}
Java tacos. Taco.
package tacos.
The import... ;
@ Data
Public class Taco {
@ NotNull
@ the Size (min=5, the message="the Name must be at further 5 character long")
private String name;
@ NotNull
@ the Size (min=1, the message="You must choose the at further 1 ingredient")
Private ListIngredients;
}
The design. The HTML
& lt; ! DOCTYPE html>XMLNS: th="http://www.thymeleaf.org" & gt;
<body>
.