简体   繁体   English

修改表格。 将ID传递为隐藏值

[英]Modify a form. Passing id as hidden value

Application: Spring MVC, Hibernate, JSP 应用程序:Spring MVC,Hibernate,JSP

Query: While modifying the form, I am passing pre-populated RECIPE object but id column is returned as NULL. 查询:在修改表单时,我正在传递预填充的RECIPE对象,但id列返回为NULL。

Recipe class has only 2 column - ID and NAME; 食谱类只有2列-ID和NAME;

@RequestMapping(value = "/modify/{id}")
public String modifyRecipe(@PathVariable int id, Model model) {
    Recipe recipe = recipeService.findRecipe(id);
    model.addAttribute("recipe", recipe);

    return "recipes/modify";
}

@RequestMapping(value = "modify", method = RequestMethod.POST)
public String updateRecipe(@Valid Recipe recip, Model model) {
    logger.info("From JSP [" + recipe + "]");

    if (result.hasErrors()) {
        return "recipes/modify";
    }
    recipeServices.updateRecipe(recipe);
    return "redirect:/recipe/" + recipe.getId();
}

JSP Page JSP页面

<body>
    <s:url value="/recipe/modify" var="recipe_modify" />
    <h2>
        Modify
        <c:out value="${fn:toUpperCase(recipe.name)}" />
    </h2>
    <sf:form modelAttribute="recipe" method="POST"
        action="${recipe_modify}">
        <fieldset>
            <table>
                <tr>
                    <th><sf:label path="name">Name of Recipe</sf:label></th>
                </tr>
                <tr>
                    <td><sf:input path="name" size="30" /> <br /> <sf:errors
                            path="name" cssClass="error"></sf:errors><br /></td>
                </tr>

When JSP is submitted following is getting passed to Spring INFO 2014-11-01 22:21:32,342 com.recipe.mvc.RecipeController - From JSP [Recipe [id=null, name=sandwich] 提交JSP时,以下信息将传递给Spring INFO 2014-11-01 22:21:32,342 com.recipe.mvc.RecipeController-来自JSP [Recipe [id = null,name = sandwich]

Why id is not getting passed here? 为什么id在这里没有传递?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM