0

私はSpringMVCで簡単なフォームを持っています。すでに持っていたBeanをpbidで取得したいです。問題は、既に設定されている Bean を取得できるサーバー側ですが、jsp 側では常に新しい Bean を取得します。@ModelAttribute("productbean") を使用していくつかのパラメーターを受け取り、サーバー側で Bean ストアを取得できますか? どうやってするの?jstl|form は常に新しいフォームを取得するようです

<form:form method="post" modelAttribute="productbean" action="">
<table>

    </tr>

    <tr>
        <td width="118"><form:label for="name" path="name" > Production Name:</form:label></td>
        <td colspan="2"><form:hidden path="pbid"/><form:input path="name" type="text" size="50" /></td>
    </tr>
...

私のコントローラーは次のようなものです:

@RequestMapping(value="/createproduct", method=RequestMethod.GET)
public  String getProduct(HttpServletRequest req, Model model, 
        @RequestParam(value = "pbid", required = false, defaultValue = "") String spbid) throws MalformedURLException {
    UUID pbid;
    if(spbid.isEmpty())pbid=UUID.randomUUID();
    else pbid=UUID.fromString(spbid);
    ProductBean tmp;
    if(!products.containsKey(pbid)){
        tmp=createbean();
        pbid=tmp.getPbid(); 
        System.err.println("============new productbean===============\n");
    }else{
        tmp=products.get(pbid);
        System.err.println(tmp.getMpf().size());
        System.err.println(tmp.getMpf().printFileNameList());
    }
 .....

@ModelAttribute("productbean")
public ProductBean createbean(){
    ProductBean productbean=new ProductBean(context.getRealPath(filepath));
    products.put(productbean.assignID(), productbean);
    return productbean;
}
4

1 に答える 1

0

クラスにセッション属性アノテーションを追加する

@SessionAttributes("productbean")
@controller
public class test() {
}
于 2012-10-17T12:41:08.717 に答える