专业人士如何诊断?我不知道这是哪里来的。
当我进行主页获取时,我得到:
java.lang.NoSuchMethodException: java.util.List.<init>()
这是主页控制器/模板:
@Controller
@Slf4j
@RequestMapping("/")
public class ReciplyController {
@Autowired
RecipeService svc;
// == Model attributes ==
@ModelAttribute
public List<Recipe> recipeData(){ return svc.getAllRecipes(); }
@ModelAttribute("allUnits")
public List<Unit> unitList() {
return Arrays.asList(Unit.ALL);
}
@RequestMapping(Mappings.HOME) // AliasFor @RequestMapping(method = RequestMethod.GET)
public String getMainView(
Model model,
@ModelAttribute(AttributeNames.RECIPE) Recipe recipe,
@ModelAttribute(AttributeNames.INGREDIENT_LIST) List<Ingredient> ingredientList) {
log.info("Inside getMainView");
if(ingredientList==null){
log.info("ingredientList==null){");
}
/* Check recipeID and ingredient list exist.
* If they don't initialize them so they can be handed to the model
*/
if (recipe == null) {
log.info("recipe==null");
recipe = new Recipe();
// Set a new recipeID
// Log the ID
recipe.setRecipeId(svc.generateId());
log.info("Attached ID {} to recipe", recipe.getRecipeId());
recipe.setIngredientList(new ArrayList<>());
log.info("Recipe ID in process: {}", recipe.getRecipeId());
log.info("Attached Ingredient List");
} else // ?recipeId set?
// ?recipe.getIngredientList() == null
{
log.info("recipe!=null");
if(recipe.getRecipeId()==null){
recipe.setRecipeId(svc.generateId()); // Set id via service
}
if(recipe.getIngredientList()==null) {
recipe.setIngredientList(new ArrayList<>()); // Initialize ingredient list
}
}
//recipe has Id
recipe.setRecipeName("Fish Pie");
recipe.getIngredientList().add(
new Ingredient(
svc.generateId(),
10.0,
Unit.CUPS.getName(),
"Sassifrasss"));
model.addAttribute(AttributeNames.RECIPE, recipe);
model.addAttribute(AttributeNames.RECIPE_ID, recipe.getRecipeId());
model.addAttribute(AttributeNames.RECIPE_NAME, recipe.getRecipeName());
model.addAttribute(AttributeNames.RECIPE_DATA, recipeData());
log.info("recipe ingredient list size: {}", recipe.getIngredientList().size());
model.addAttribute(AttributeNames.INGREDIENT_LIST, recipe.getIngredientList());
return ViewNames.HOME;
}
}
模板:
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link rel="stylesheet" type="text/css" media="all"
href="../static/css/home-style.css"
th:href="@{/css/home-style.css}"/>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h4>For the future, creating the template has 3 phases:
<ol>
<ul>Test data binding "Data draft"</ul>
<ul>Mockup without data "Visual draft"</ul>
<ul>Final product</ul>
</ol>
</h4>
<!---->
<h1 id="page-title"/>
<h3 id="recipe-id"/>
<h3 id="recipe-name"/>
<!--Atm, one object is used to pass data back and
forth between view and handler -->
<form id="add-rows-form" action="#" method="post">
<label id="add-rows-label" for="add-rows-input"></label>
<input id="add-rows-input" type="number" name="add-rows-name"/>
<input id="submit-add-row" type="submit" th:value="#{table.add.row}"/>
</form>
<form id="get-recalculated-recipe" action="#" method="post">
<table>
<tr>
<th th:text="#{table.label.quantity}">Quantity</th>
<th>Unit</th>
<th>Ingredient Name</th>
<th>Multiplier</th>
</tr>
<!-- Create div body unless ingredientlist is empty.
This should happen once per recipe added through front-end
-->
<div class="ingredienttable" th:unless="${#lists.isEmpty(ingredientlist)}">
<tr th:each="ingredient, iter : ${ingredientlist}">
<td>
<input id="table-quantity"/>
</td>
<td>
<input id="table-unit"/>
</td>
<td>
<input id="table-name"/>
</td>
<!-- <td>-->
<!-- <input type="checkbox" name="multCheckbox"/>-->
<!-- </td>-->
<!-- <td>-->
<!-- <input id="choose-mult"/>-->
<!-- </td>-->
<th>
<button type="submit" name="addRow" th:text="#{table.mult.row}">Add row</button>
</th>
</tr>
</div>
</table>
</form>
</div>
</body>
</html>