有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java在输入框中设置默认值,crud应用程序使用spring

我试图使用Spring MVC制作一个CRUD应用程序,但是每当我点击编辑按钮来更新一行中的条目时,我编辑条目的jsp页面(wizardeditform.jsp)就会用正确的值填充该条目中的“指定”和“wand”输入。我希望所有的输入框都有该行的默认值,而不仅仅是“魔杖”和“指定”输入框。有人知道为什么会这样吗?(我一直在学习本教程:http://www.javatpoint.com/spring-mvc-crud-example

wizardeditform。jsp

<h1>Edit Witch or Wizard</h1>
<form:form method="POST" action="/WizardingWorld/editsave">
    <table>
        <tr>
            <td></td>
            <td><form:hidden path="id" /></td>
        </tr>
        <tr>
            <td>First name :</td>
            <td><form:input path="firstname"/></td>
        </tr>
        <tr>
            <td>Last name :</td>
            <td><form:input path="lastname" /></td>
        </tr>
        <tr>
            <td>Designation :</td>
            <td><form:input path="designation"/></td>
        </tr>
        <tr>
            <td>School and house :</td>
            <td><form:input path="schoolAndHouse" /></td>
        </tr>
        <tr>
            <td>wand :</td>
            <td><form:input path="wand" /></td>
        </tr>
        <tr>
            <td>Blood Type</td>
            <td><form:input path="bloodtype" /></td>
        </tr>
        <tr>
            <td></td>
            <td><input type="submit" value="Save" /></td>
        </tr>
    </table>
</form:form>

控制器类

// displays form to input data, "command" is request attr. used to display
// object data into form
@RequestMapping("/wizardform")
public ModelAndView showform() {
    return new ModelAndView("wizardform", "command", new Wizard());
}

// saves object into database. The @ModelAttribute puts request data into
// model object.
@RequestMapping(value = "/save", method = RequestMethod.POST)
public ModelAndView save(@ModelAttribute("wizard") Wizard wizard) {
    dao.save(wizard);
    return new ModelAndView("redirect:/viewwizard");// will redirect to
                                                    // viewwizard request
                                                    // mapping
}

// provides list of employees in model object
@RequestMapping("/viewwizard")
public ModelAndView viewwizard() {
    List<Wizard> list = dao.getWizards();
    return new ModelAndView("viewwizard", "list", list);
}

// It displays object data into form for the given id. The @PathVariable
// puts URL data into variable
@RequestMapping(value = "/editwizard/{id}")
public ModelAndView edit(@PathVariable int id) {
    Wizard wizard = dao.getWizardById(id);
    return new ModelAndView("wizardeditform", "command", wizard);
}

// updates model object
@RequestMapping(value = "/editsave", method = RequestMethod.POST)
public ModelAndView editsave(@ModelAttribute("wizard") Wizard wizard) {
    dao.update(wizard);
    return new ModelAndView("redirect:/viewwizard");
}

第一个图像是查看所有表条目的jsp页面,第二个图像是wizardeditform。jsp,在单击上一页上包含所有条目的编辑按钮之后

this is the jsp page to view all the entries

this is the wizardeditform.jsp , right after clicking the edit button on the previous page


共 (0) 个答案