多表单同时修改 Freemarker + controller + service

来源:互联网 发布:php就业方向 编辑:程序博客网 时间:2024/05/21 13:22
controller:@RequestMapping("/allSave")    public String allSave(@RequestParam(value = "effectData") String effectData, RedirectAttributesModelMap model, HttpSession httpSession) {        try {            OperatorDO opDo = (OperatorDO) httpSession.getAttribute(Constant.SESSION_USER_KEY);// 获取当前用户            String parentId = (String) httpSession.getAttribute(SESSION_LAW02_PARENTID);                        law01Service.allSave(effectData,opDo.getName());            model.addAttribute("id", parentId);            model.addFlashAttribute(Constant.MESSAGE, " 操作成功。");        } catch (Exception e) {            model.addFlashAttribute(Constant.ERRMSG, " 出现错误,操作失败");        }        return "redirect:/law02/show";
service:public void allSave(String effectData,String loginUser) {            if (StringUtils.isEmpty(effectData)) {            return;        }        String[] rows = effectData.split(";");                if (rows == null) {<pre name="code" class="javascript">
<pre name="code" class="java"><pre name="code" class="javascript">js:function allSave(){        var tableData = ""; //存所有数据        $("#lawFileList tr:not(:first)").each(function(){ //遍历除标题行外所有行            var rowData="[";            $("input",this).each(function(){ //遍历行内的input 的值id                rowData+=$(this).val();            });            rowData+=",";            $("select",this).each(function(){ //遍历行内的select的值效力范围                rowData+=$(this).val();            });            rowData+="]";            tableData+=rowData+";"; //全部数据, 行与行之间“;”隔开        });                tableData = tableData.substring(0, tableData.length-1);        if (tableData.length<=0) {            return;        }                $('#effectData').val(tableData);        $("#effectModForm").attr("method", "POST");        $("#effectModForm").submit();    }

return; } for (int i=0; i<rows.length;i++) { String[] rowData = rows[i].replace("[", "").replace("]", "").split(","); String id = rowData[0]; String effectId = rowData[1]; LawDO law = lawDAO.getLawById(id); if (law!=null) { if (law.getEffectId()!=Integer.valueOf(effectId)) { law.setEffectId(Integer.valueOf(effectId)); law.setUpdUser(loginUser); lawDAO.updateLawEffect(law); } } } }

freemaker:<table class="table table-bordered table-striped" id="lawFileList"><tbody>            <tr>                <th style="display:none;">ID</th>                <th width="20%">文件名称</th>                <th width="20%">内容</th>                <th width="20%">效力范围</th>                 <th width="20%">操作</th>            </tr><#list listFile! as x><tr><td style="display:none;"><input  type ="text"value ="${x.id!}" /></td><td>${x.title!}</td><td><a href="http://121.40.84.119:8080/lvshitongfile/upload${(x.content)!}" target="_blank">点击查看内容</a></td><td> <select  class="input input-auto"  value="${(x.effectId)!}" >  <option value ="1102" <#if ((x.effectId!'')?string == '1102')> selected="selected" </#if>  selected="selected" >法律</option>  <option value ="1103" <#if ((x.effectId!'')?string == '1103')> selected="selected" </#if> >司法解释</option>  <option value ="1104" <#if ((x.effectId!'')?string == '1104')> selected="selected" </#if> >行政法规</option>  <option value ="1105" <#if ((x.effectId!'')?string == '1105')> selected="selected" </#if> >规章及其他</option></td><td><a   onclick="confirmDeleteFile('${(x.title)!}','${(x.content)!}')">删除</a></td></tr ></#list>            </tbody>    </table>    <br/>  <form id="effectModForm" method ="post" action ="${base}/law02/allSave">  <input type="hidden" name="effectData" id="effectData">  </form>   <button class="button bg-main" onclick ="allSave()">全部保存</button>



0 0