使用spring MVC将文件夹上传到mysql时出错

我正在构建一个应用程序。用户将查看一个页面,用户应输入患者代码和以下描述,然后用户将上传包含 CSV 文件的文件夹。我正在尝试使用 spring MVC - JSP 上传“由 CSV 文件组成的文件夹”(不是 zip/rar 文件)


这是我的 JSP 代码:


<div class="w3-row w3-section">

                        <div class="w3-col" style="width:200px">* Patient code</div>

                        <div class="w3-rest">

                            <%--<form:select path="patient">--%>

                                <%--<form:options items="${patient}" itemLabel="name" itemValue="id"/>--%>

                            <%--</form:select>--%>

                                <form:input type="text" path="id_patient" name="id_patient" id="id_patient" placeholder="input number 1-20" class="w3-input w3-border"/>

                        </div>

                    </div>


                    <div class="w3-row w3-section">

                        <div class="w3-col" style="width:200px">* Patient description</div>

                        <div class="w3-rest">

                            <form:input type="text" path="description" name="description" id="description" placeholder="put any description" class="w3-input w3-border"/>

                        </div>

                    </div>


                    <div class="w3-row w3-section">

                        <div class="w3-col" style="width:200px">* Input Data Files</div>

                        <div class="w3-rest">

                            <input type="file" path="fileName" name="attachFileObj" webkitdirectory directory />

                        </div>

                    </div>

这是我的 Patient.java 文件:


public class Patient {


    //field patient

    private int id_patient;

    private String description;

    private String patient;



    public String getDescription() {

        return description;

    }


    public void setDescription(String description) {

        this.description = description;

    }


    public int getId_patient() {

        return id_patient;

    }


    public void setId_patient(int id_patient) {

        this.id_patient = id_patient;

    }




慕尼黑的夜晚无繁华
浏览 175回答 2
2回答

倚天杖

我认为您不能同时运行这两个:if(null != jdbcTemplate) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Performing The Sql 'Insert' Operation&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String sql = "insert into patient(id_patient, description) values(?,?);" +&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "insert into attachment(id_data, file_data, patientID) values (?, ?, (select patientID from patient where patientID = id_patient));";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jdbcTemplate.update(sql, patient.getDescription(), attachment.getId_data(), attachment.getData(), attachment.getPatientID());也许尝试:&nbsp; &nbsp; if(null != jdbcTemplate) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Performing The Sql 'Insert' Operation&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String sql = "insert into patient(id_patient, description) values(?,?);";&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String sqlTwo = "insert into attachment(id_data, file_data, patientID) values (?, ?, (select patientID from patient where patientID = id_patient));";jdbcTemplate.update(sql, patient.getDescription(), attachment.getId_data(), attachment.getData(), attachment.getPatientID());jdbcTemplate.update(sqlTwo, patient.getDescription(), attachment.getId_data(), attachment.getData(), attachment.getPatientID());还您不能使用嵌套子查询绑定参数:values (?, ?, (select patientID from patient where patientID = id_patient))
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java