s2sh框架整合struts2的<s:select> 如何获取选中的值传入数据库MySQLselect中选项是true、false        (对应POJO类Vote的属性restrictId)要传入数据库的字段类型为TINYINT(1) (对应表vote_topic  字段:restrict_user_id)
比如选中true   传入数据库的值为:1请问该如何实现???或者用单选框radio  又该如何实现?这问题困恼好几天了

解决方案 »

  1.   

    用<s:if test=""></if:s>判断。。
      

  2.   

    页面
    <s:select name = "restrictId" list="#{1:'true',2:'false'}" theme="simple">
    </s:select>后台action 内包含一个 
    private Integer restrictId;
    并生成getter setter方法。
    这里action里面就可以取到你前台选择的那个id值了,保存到你的pojo 然后持久化吧。
      

  3.   

    <s:select> 中的name 属性有关
      

  4.   


    同样通过action 里面的 
    private Integer restrictId;
    在你跳转到你的修改页面之前将 restrictId 初始化。
    <s:select name = "restrictId" list="#{1:'true',2:'false'}" theme="simple">
    </s:select>
    会根据restrictId 的值来选中的。
      

  5.   

    单选和多选框如何通过获取数据库字段值来判断单选和多选框的选中状态
    这个我实现了,代码如下:
    <input type="checkbox" name="vote.currentVote" <s:if test="%{vote.currentVote}">checked="checked"</s:if> value="true" >
      

  6.   

    个人认为是正确的,我一开始也是不明白,但用单选按钮测试之后,就明白了。
    那就是在你不选中单选按钮提交的情况的话,所传的的参数为你原来从数据库中传来的值。
    拿性别举例啊!<tr>
    <td>
    性别:
    </td>
    <td>
    <s:if test="#list.sex==0">
    <input name="sex" type="radio" value="0" checked />男
    <input name="sex" type="radio" value="1"/>女
    </s:if>
    <s:else>
    <input name="sex" type="radio" value="0" />男
    <input name="sex" type="radio" value="1" checked />女
    </s:else>
    </td>
    </tr>当你传过来是0时,在前台页面是显示男被选中状态的,如果不改变的话,传回去的参数还是0.
    如果在显示单选按钮中选择了女,那么传回去的参数为1,对数据库更新。
    是不是lz 想要的答案?!
      

  7.   

    struts2标签已经实现了这个功能了。
      

  8.   

    <s:select name="vote.currentVote" list="#{0 : 'false', 1 : 'true'}"></s:select> 
      

  9.   

    struts2标签已经实现了这个功能了!!!!!!!!!!!!!