thinkphp 自动接收表单数据进行更新

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/moniteryao/article/details/54946005

$post=D("term_relationships");
$post->create();//自动接收表单数据
$result=$post->where("tid=".$post->tid)->save();//根据条件更新数据

说明:

form中控件的name要与数据库字段名相同,

还需要一个隐藏域,name为id,

简单的说,需要用到的字段,都要有dom的name来对应。



展开阅读全文

Controller接收不到表单数据

11-10

1、实体类Khlx.javarnpackage lankey.model;rnrnimport java.io.Serializable;rnrnpublic class Khlx implements Serializablernrn /**rn * rn */rn private static final long serialVersionUID = 1L;rn private String idx;rn private String namex;rn private String sign;rn private String bz;rn public Khlx() rn rn // TODO Auto-generated constructor stubrn rn public Khlx(String idx, String namex, String sign, String bz) rn super();rn this.idx = idx;rn this.namex = namex;rn this.sign = sign;rn this.bz = bz;rn rn public String getIdx() rn return idx;rn rn public void setIdx(String idx) rn this.idx = idx;rn rn public String getNamex() rn return namex;rn rn public void setNamex(String namex) rn this.namex = namex;rn rn public String getSign() rn return sign;rn rn public void setSign(String sign) rn this.sign = sign;rn rn public String getBz() rn return bz;rn rn public void setBz(String bz) rn this.bz = bz;rn rnrn public static long getSerialversionuid() rn return serialVersionUID;rn rn @Overridern public String toString() rn return "Khlx [idx=" + idx + ", namex=" + namex + ", sign=" + signrn + ", bz=" + bz + "]";rn rn rnrnrnrn2、表单insertKhlx.jsprn<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>rn<%@taglib prefix="form" uri="http://www.springframework.org/tags/form" %>rn<%rnString path = request.getContextPath();rnString basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";rn%>rnrnrnrn rn rn rn 增加表格类型档案rn <%rn Map map=new HashMap();rn map.put("0", "停用");rn map.put("1","启用");rn request.setAttribute("sign", map);rn %>rn rn rn rn rn rn rn rn rn 编号rn rn rn rn 名称rn rn rn rn 启用标识rn rn rn rn 备注rn rn rn rn rn rn rn rn rn rn <%-- rn rn rn 编号rn rn rn rn 名称rn rn rn rn 启用标识rn rn rn rn 备注rn rn rn rn rn rn rn rn rn --%>rn rn rnrn3、控制器类KhlxController.javarnrnpackage lankey.controller;rnrnimport java.io.IOException;rnimport java.util.Map;rnrnimport javax.servlet.http.HttpServletRequest;rnimport javax.servlet.http.HttpServletResponse;rnimport javax.validation.Valid;rnrnimport lankey.model.Khlx;rnimport lankey.service.KhlxService;rnimport lankey.util.RefererTools;rnrnimport org.springframework.beans.factory.annotation.Autowired;rnimport org.springframework.stereotype.Controller;rnimport org.springframework.validation.BindingResult;rnimport org.springframework.validation.FieldError;rnimport org.springframework.web.bind.annotation.ModelAttribute;rnimport org.springframework.web.bind.annotation.RequestMapping;rnimport org.springframework.web.bind.annotation.RequestMethod;rnimport org.springframework.web.bind.annotation.RequestParam;rnrn@Controllerrnpublic class KhlxController rn @Autowiredrn private KhlxService khlxService;rn @ModelAttributern public void getKhlx(@RequestParam(value="idx",required=false) String idx,Mapmap)rn rn if(idx!=null||!("".equals(idx)))rn rn map.put("khlx", khlxService.getKhlx(idx));rn rn rn @RequestMapping(value="khlxSave",method=RequestMethod.POST )rn public String khlxSave(@ModelAttribute Khlx khlx,HttpServletRequest request)rn rn System.out.println(request.getParameter("namex"));rn khlxService.insertKhlx(khlx);rn return "redirect:/getAllKhlx";rn rn @RequestMapping("addKhlx")rn public String addKhlx (Mapmap)rn rn map.put("khlx", new Khlx());rn return "insertKhlx";rn rnrn4、问题:@RequestMapping(value="khlxSave",method=RequestMethod.POST )rn public String khlxSave(@ModelAttribute Khlx khlx,HttpServletRequest request)中khlx没接收到传过来的类,值为null,但是System.out.println(request.getParameter("namex"));确能打印得出正确值。rnrn 论坛

表单数据为什么没有更新

04-16

我用js做了一个功能:rn在一个表单中共有三个按钮和两个(左,右)可多选的select项,点第一个按钮让数据从左边的select项中移到右边。第二个相反。第三个是表单提交。rnrn我执行了数据从左边移到了右边。而且左边消失了,右边增加了。可是提交表单时,数据还是最初的数据(移动前的数据),rn为什么,麻烦哪位高手帮忙看看。代码如下:rnrnjs代码:rn // 提交表单用rn function deviceManagerApply(path)rn rn document.deviceManagerForm.action=path;rn document.deviceManagerForm.submit();rn rn rn //向左面添加选项rn function mvToLeftLine(lobj, robj)rn var selectLines = document.getElementById("inGrpDevice");rn var lLine = document.getElementById("unGrpDevice");rn rn for(var i = 0; i < selectLines.length; i++)rn if (selectLines.options[i].selected)rn // 向左面添加选项rn var opt = new Option(selectLines.options[i].value, selectLines.options[i].value);rn //var opt = new Option(selectLines.options[i].value, lLine.length + i);rn lobj.options.add(opt);rn rn rn for(var j = selectLines.length -1; 0 <= j; j--)rn if(selectLines.options[j].selected)rn // 从右面删除选项rn selectLines.options.remove(j);rn rn rn rn // 向右边添加选项rn function mvToRightLine(lobj, robj)rn var selectLines = document.getElementById("unGrpDevice");rn var rLine = document.getElementById("inGrpDevice");rn for (var i = 0; i < selectLines.length; i++)rn if (selectLines.options[i].selected)rn // 向右面添加选项rn var opt = new Option(selectLines.options[i].value, selectLines.options[i].value);rn //var opt = new Option(selectLines.options[i].value, rLine.length+i);rn robj.options.add(opt);rn rn rn rn rn for (var j = selectLines.length -1; 0 <= j; j--)rn if (selectLines.options[j].selected)rn rn // 从左面删除选项rn selectLines.options.remove(j);rn rn rn rnrn表单代码:rn rnrnrnrnrnrn 论坛

没有更多推荐了,返回首页