2

在下面的代码中,我正在获取列表并正确查看,但是在更新时我只面对连接的第一个字段 rsoCode 例如,如果我的 rsoCode 是NH43,那么它将作为NH43,NH43进入控制器。在更新表单中它显示正确,但是当涉及到

在调试时,我观察到 getRsoCode() 在更新屏幕时调用了两次(我们可以在其中更改值)。

这是JSP代码

<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<form:form action="" method="POST" commandName="updateRso">
<table>
    <tr>
        <td style="font-weight: bold; font-variant: small-caps;">RSO Code:</td>
        <td><form:input path="rsoCode" value="${updateRso.rsoCode}" disabled="disabled"/></td></tr>

    <tr><td style="font-weight: bold; font-variant: small-caps;">RSO Description:</td>
        <td><form:input path="rsoDescriprion" value="${updateRso.rsoDescriprion}"/></td>
    </tr>
    <tr>
        <td style="font-weight: bold; font-variant: small-caps;">Region Code:</td>
        <td><form:input path="regionCode" value="${updateRso.regionCode}"/></td></tr>
        <tr><td style="font-weight: bold; font-variant: small-caps;">Region Description:</td>
        <td><form:input path="regiondescription" value="${updateRso.regiondescription}"/></td>
    </tr>
    <tr>
        <td colspan="10" align="center">&nbsp;&nbsp;&nbsp;<input type="submit" value="Submit"/> </td>
    </tr>
    </table>
    </form:form>

控制器代码

@Controller
public class ListRsoController {

    private static final Logger logger = LoggerFactory.getLogger(ListRsoController.class);

    @ModelAttribute("updateRso")
    public ListRso getListRso()
    {

        ListRso updateRso = new ListRso();

        return updateRso;
    }

    @RequestMapping(value="listrso")
    public String listAllRso(ModelMap model) throws Exception{

        ListRsoDao listDao = new ListRsoDao();

        model.addAttribute("rsos", listDao.getList());

        return "listrso/view";
    }

    @RequestMapping(value="getRsoDetails")
    public String getRso(@RequestParam("rsoCode")String rsoCode, ModelMap model,HttpServletRequest req) throws Exception{

        ListRsoDao lstdto = new ListRsoDao();

        Object obj = lstdto.getRsoCode(rsoCode);

        model.addAttribute("savedClass", obj);

        return "listrso/viewdetails";
    }
    @RequestMapping(value="updateRsoDetails", method=RequestMethod.GET)
    public String updateRso(@RequestParam("rsoCode")String rsoCode, ModelMap model,HttpServletRequest req) throws Exception{

        ListRsoDao lstdto = new ListRsoDao();

        Object obj = lstdto.getRsoCode(rsoCode);

        model.addAttribute("updateRso", obj);

        return "listrso/updatedetails";

    }

    @RequestMapping(value="deleteRsoDetails")
    public String deleteRso(@RequestParam("rsoCode")ListRso rsoCode, ModelMap model,HttpServletRequest req) throws Exception{

        ListRsoDao lstdto = new ListRsoDao();

        lstdto.deleteRso(rsoCode);

        //model.addAttribute("savedClass", obj);

        return "listrso/deleteSuccess";
    }

    @RequestMapping(method = RequestMethod.POST, value="updateRsoDetails")
    protected String onSubmit( @ModelAttribute("updateRso") ListRso rsoCommand,  ModelMap model ) throws Exception
    {
        model.clear();
        new  ListRsoDao().updateRso(rsoCommand);
        model.addAttribute("savedClass", rsoCommand);
        return "listrso/view";
    }

}

爪哇豆

public class ListRso {

    private String rsoCode;
    private String rsoDescriprion;
    private String regionCode;
    private String regiondescription;

    public ListRso(String rsoCode, String rsoDescriprion, String regionCode,
            String regiondescription) {
        super();
        this.rsoCode = rsoCode;
        this.rsoDescriprion = rsoDescriprion;
        this.regionCode = regionCode;
        this.regiondescription = regiondescription;
    }

    public ListRso(String rsoCode)
    {
        this.rsoCode = rsoCode;
    }
    public ListRso() {
        // TODO Auto-generated constructor stub
    }
    public String getRsoCode() {
        return rsoCode;
    }
    public void setRsoCode(String rsoCode) {
        this.rsoCode = rsoCode;
    }
    public String getRsoDescriprion() {
        return rsoDescriprion;
    }
    public void setRsoDescriprion(String rsoDescriprion) {
        this.rsoDescriprion = rsoDescriprion;
    }
    public String getRegionCode() {
        return regionCode;
    }
    public void setRegionCode(String regionCode) {
        this.regionCode = regionCode;
    }
    public String getRegiondescription() {
        return regiondescription;
    }
    public void setRegiondescription(String regiondescription) {
        this.regiondescription = regiondescription;
    }


}
4

2 回答 2

3

您的表单没有任何操作,这会导致弹簧标签做奇怪的事情。和这个 :

<form:form action="" method="POST" commandName="updateRso">

意味着您只需要这样做(删除 value 属性,输入是从路径填充的)

<table>
    <tr>
        <td style="font-weight: bold; font-variant: small-caps;">RSO Code:</td>
        <td><form:input path="rsoCode" disabled="disabled"/></td>
于 2013-04-10T09:18:14.527 回答
0

最近我遇到了类似的问题问题的根本原因是我定义了两次相同的路径变量,一个在屏幕上可见,另一个被隐藏。在提交表单时,commqnd 将值与相同的路径/名称连接起来。要解决此问题,您已删除隐藏的。

希望这些信息有帮助

于 2019-03-16T00:25:51.810 回答