NutzCN Logo
问答 上传图片上传不了,点击上传图片提交上去空的,别的字段也为空????
发布于 70天前 作者 qq_bd0f335e 155 次浏览 复制 上一个帖子 下一个帖子
标签: nutzwk

点击图片上传提交的时候把其他字段也为空了这是怎么回事,大神指教一下??????????

前台代码

<%
layout("/layouts/platform.html"){
%>
<script src="${base!}/assets/plugins/ueditor/ueditor.config.js"></script>
<script src="${base!}/assets/plugins/ueditor/ueditor.all.min.js"></script>
<header class="header navbar bg-white shadow">
    <div class="btn-group tool-button">
        <a class="btn btn-primary navbar-btn" href="${base}/platform/iff/article" id="goBack" data-pjax><i class="ti-angle-left"></i>返回</a>
    </div>
</header>

<div class="content-wrap">
    <div class="wrapper" style="min-height:500px;">

            <form id="addForm" role="form" class="form-horizontal parsley-form" data-parsley-validate
                  action="${base}/platform/iff/article/addDo" method="post">
                    <div class="col-lg-12">
                  
                        <div class="form-group">
                            <label for="title" class="col-sm-2 control-label">文章标题</label>
                            <div class="col-sm-8">
                                <input type="text" id="title" class="form-control" name="title" data-parsley-required="true"
                                       placeholder="文章标题" value="" >
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="authorId" class="col-sm-2 control-label">文章作者</label>
                            <div class="col-sm-8">
                                <input type="text" id="authorId" class="form-control" name="authorId"
                                       placeholder="文章作者" value="${username!}" >
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="info" class="col-sm-2 control-label">文章简介</label>
                            <div class="col-sm-8">
                                <textarea id="info" name="info" class="form-control" style="width:100%;height:80px;"></textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="releaseDate" class="col-sm-2 control-label">发布时间</label>
                            <div class="col-sm-8 input-group date form_datetime " style="padding-left: 16px;padding-right: 16px;" data-date="1979-09-16T05:25:07Z" data-date-format="dd MM yyyy - HH:ii p" data-link-field="releaseDate">
                                <input type="text" size="16" readonly class="form-control" value="${@date.getDateTime()}" data-parsley-required="true">
                                <span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
                                <span class="input-group-addon"><span class="glyphicon glyphicon-th"></span></span>
                            </div>
                            <input type="hidden" id="releaseDate" name="releaseDate" value="${@date.getDateTime()}" />
                        </div>
                        <div class="form-group">
                            <label for="disabled" class="col-sm-2 control-label">取消发布</label>
                            <div class="col-sm-8 switcha">
                                <div class="mr15">
                                    <input type="checkbox" id="disabled" name="disabled" class="js-switch-blue" value="true" >
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="picurl" class="col-sm-2 control-label">标题图</label>

                            <div class="col-sm-8">
                                <div id="queue"></div>
                                <div>
                                    <input id="file_upload" name="file_upload" type="file" multiple="false">
                                </div>
                                <div id="img" style="padding: 5px;">
                                </div>
                                <input type="hidden" id="picurl" name="picurl" value="" >
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="content" class="col-sm-2 control-label">文章内容</label>

                            <div class="col-sm-8">
                                <textarea id="content" name="content" style="width:100%;height:200px;"></textarea>
                            </div>
                        </div>
                    </div>
                <div class="col-lg-3"></div>
                <div class="col-lg-6">
                    <div class="form-group text-center">
                        <label></label>

                        <div>
                            <button class="btn btn-primary btn-block btn-lg btn-parsley" data-loading-text="正在提交..." >提 交</button>
                        </div>
                    </div>
                </div>
            </form>
    </div>
</div>


<script language="JavaScript">
    function clearFile() {
        $("#img").html("");
        $("#queue").html("");
        $("#picurl").val("");
    }

    var ue;
    $(document).ready(function () {
        setTimeout(function () {
            ue= new baidu.editor.ui.Editor();
            ue.render('content');
        },500);
        myForm.init();
        $('.form_datetime').datetimepicker({
            language:  'zh-CN',
            format:'yyyy-mm-dd hh:ii:ss',
            weekStart: 1,
            todayBtn:  1,
            autoclose: 1,
            todayHighlight: 1,
            startView: 2,
            forceParse: 0,
            showMeridian: 1
        });

        $('#file_upload').uploadifive({
            'auto': true,
            'multi': false,
            'width': '100%',
            'height': '35',
            'buttonText': '请选择图片',
            'fileType': 'image/jpg,image/jpeg,image/png',
            'fileSizeLimit': 1024,
            'queueSizeLimit': 1,
            'formData': {},
            'queueID': 'queue',
            'uploadScript': '${base}/open/file/upload/image',
            'onUploadComplete': function (file, data) {
                data = JSON.parse(data);
                if (data.code == 0) {
                    Toast.success(data.msg);
                    $("#img").html("<img src='" + data.data + "' style='width:150px;height:95px;'>");
                    $("#picurl").val(data.data);
                } else {
                    clearFile();
                    Toast.error(data.msg);
                }
            },
            'onDrop': function (file, fileDropCount) {
                clearFile();
            },
            'onClearQueue': function (queue) {
                clearFile();
            },
            'onCancel': function () {
                clearFile();
            }
        });

        $('#addForm').ajaxForm({
            dataType: 'json',
            beforeSubmit: function (arr, form, options) {
                sublime.showLoadingbar($(".main-content"));
            },
            success: function (data, statusText, xhr, form) {
                if (data.code == 0) {
                    Toast.success(data.msg);
                } else {
                    Toast.error(data.msg);
                }
                sublime.closeLoadingbar($(".main-content"));
            }
        });

    });
</script>
<%}%>


后台代码
   @At("/addDo")
    @Ok("json")
    @RequiresPermissions("platform.iff.article.add")
    @SLog(tag = "图文表", msg = "${args[0].id}")
    public Object addDo(@Param("..")Iff_article iffArticle, HttpServletRequest req) {
		try {
			iffArticleService.insert(iffArticle);
			return Result.success("system.success");
		} catch (Exception e) {
			return Result.error("system.error");
		}
    }
12 回复

另外,带文件上传的表单,后台要加上适配器:

@AdaptBy(type = WhaleAdaptor.class)

搜一下,其他类似地方都有加。

有的,我在页面提交的时候把添加所有的都为空了,大神帮帮忙看看

大神还是不行,我写的另一个就可以,这个就不行,不知道什么原因

  'formData': {},

你都没传表单数据

我的另一个也是这么写的都能上传上去, 'formData': {},这个怎么传表单数据

我要是不上传图片,其他的都能添加成功

查uploadifive的文档

@AdaptBy(type = WhaleAdaptor.class)加在后台方法上,
图片是先上传的,提交表单提交的是图片地址,默认适配器是名值对,所以要改一下WhaleAdaptor

日期 显示出来的是这样的 Tue Jul 10 16:51:40 CST 2018 怎么转换,我的数据库里是datetime类型

<div class="form-group">
                            <label for="releaseDate" class="col-sm-2 control-label">发布时间</label>
                            <div class="col-sm-8 input-group date form_datetime " style="padding-left: 16px;padding-right: 16px;" data-date="1979-09-16T05:25:07Z" data-date-format="dd MM yyyy - HH:ii p" data-link-field="releaseDate">
                                <input type="text" size="16" readonly class="form-control" value="${obj.releaseDate}" data-parsley-required="true">
                                <span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
                                <span class="input-group-addon"><span class="glyphicon glyphicon-th"></span></span>
                            </div>
                            <input type="hidden" id="releaseDate" name="releaseDate" value="${obj.releaseDate}" />
                        </div>
添加回复
请先登陆
回到顶部