表单提交到struts2 和表单提交到springmvc的controller

来源:互联网 发布:基金选择 知乎 编辑:程序博客网 时间:2024/06/16 10:03

我们直接上例子吧。

<form id="sampleform" method="post" action="addstore.html">
<fieldset>

<p>
<label class="required" for="name">名称:</label><br /> <input
type="text" id="name" class="half" name="storeInfo.name"
onblur="checkName(id);" />
</p>

<p>
<label class="required" for="mallStatus">店铺类别:</label><br /><select
id="mallStatus" class="input-text" style="width: 180px;"
name="storeInfo.mallStatus">
<s:iterator value="mallstatus" var="temp">
  <option value="${temp }">${temp.value }</option>
</s:iterator>
</select>
</p> 

<p>
<label class="required">所属频道:</label><br /> <select
class="input-text" name="storeInfo.channel" style="width: 180px;">
  <option value="10">频道</option>
   
</select>
</p> 


<p>
<label class="required" for="address">公司地址:</label><br /> 
<table>
      <tr>
<td><select name="new_province"id="new_province"
class="ordslt" onchange="changeprovice()"><option
value="0">请选择...</option>
<s:iterator value="catalogAddressOneList" var="var">
 <option value="${var.id }">${var.name }</option>
</s:iterator>
</select> 
</tr>

</table>
</p>



<p>
<label class="required">是否vip:</label><br /> <input type="radio"
id="isVip1" class="" value="false" name="storeInfo.vip"
checked="checked" /> <label class="choice" for="dateformat1">否</label>
<input type="radio" id="isVip2" class="" value="true"
name="storeInfo.vip" /> <label class="choice" for="dateformat2">是</label>
</p>

<p class="box">
<input type="submit" class="btn btn-green big" value="确定" /> <input
type="reset" class="btn btn-green big" value="重置" /> <input
type="button" class="btn btn-green big" onclick="goBack();"
value="返回" />
</p>


</fieldset>


</form>

我们看标红的。。数据库中应有StoreInfoEntity 并且该实体应该有标红的字段。

Action中只用 使用   private StoreInfoEntity storeInfo;   实现其get和set方法。

这里尤其看一下  select  和radio 中name的写法 



在springmvc中 所有的字段名字跟实体属性的名字一样就可以,不需要使用store.name,直接使用name 即可。

接收使用  @ModelAttribute(value="storeInfo") StoreInfoEntity storeInfo



0 0