V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
sdenbi
V2EX  ›  问与答

一个关于表单数据无法写入到数据库的问题,特来求助。。。

  •  
  •   sdenbi · 2016-04-24 15:25:04 +08:00 · 1349 次点击
    这是一个创建于 2943 天前的主题,其中的信息可能已经有所发展或是发生改变。

    /** * 保存操作 * * @param request * @param response * @throws IOException */ @RequestMapping(value = "saveProduct.do", method = RequestMethod.POST) public void saveProduct(HttpServletRequest request, HttpServletResponse response) throws IOException { boolean isTrue = true; String msg = "操作成功"; try { // 从上下文获取当前登录用户信息 SessionUser sessioUser = (SessionUser) request.getSession().getAttribute(SessionConstant.USER); if (sessioUser != null && StringUtils.isNotBlank(sessioUser.getUserId())) { Product po = this.getFormParameter(request, response); po.setSupId(sessioUser.getUserId()); // 保存 this.productService.addOrModifyProduct(po); } } catch (Exception e) { e.printStackTrace(); isTrue = false; msg = "操作失败"; } JSONObject jobj = new JSONObject(); jobj.put("result", isTrue); jobj.put("msg", msg); AjaxUtil.writeResult(response, jobj); }

    //发布产品

    <script> $(function(){ $("#savepro_and_next").unbind("click").on("click",function(){ var formData = $("#rqFrom").serializeArray(); var fmdata = {}; $.each(formData, function() { var name = this.name; fmdata[name] = this.value; }); fmdata.userId = "user_id_004"; $.post("${contextPath}/wechat/saveProduct.do", fmdata, function(data) { if (data.result) { //alert("保存成功"); } else { alert(data.msg); //跳转到登陆界面 } }); }); }) </script>
    2 条回复    2016-04-24 17:18:28 +08:00
    Ouyangan
        1
    Ouyangan  
       2016-04-24 16:39:20 +08:00 via Android
    排版
    jsonline
        2
    jsonline  
       2016-04-24 17:18:28 +08:00 via Android
    log
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1143 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 18:42 · PVG 02:42 · LAX 11:42 · JFK 14:42
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.