sdenbi
V2EX  ›  问与答

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

  •  
  •   sdenbi · Apr 24, 2016 · 1707 views
    This topic created in 3695 days ago, the information mentioned may be changed or developed.

    /** * 保存操作 * * @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 replies    2016-04-24 17:18:28 +08:00
    Ouyangan
        1
    Ouyangan  
       Apr 24, 2016 via Android
    排版
    jsonline
        2
    jsonline  
       Apr 24, 2016 via Android
    log
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2929 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 13:46 · PVG 21:46 · LAX 06:46 · JFK 09:46
    ♥ Do have faith in what you're doing.