天生牛马圣体 2018-05-16 14:48 采纳率: 20%
浏览 857
已结题

spring mvc写上传txt文档到mysql数据库中,报错不知道怎么解决

FileUpAndDownController.java

 package com.xx.persistence;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

@Controller
public class FileUpAndDownController {

    @RequestMapping(value = "/fileUpload")
    public String upload(
            @RequestParam(value = "file", required = false) MultipartFile file,
            HttpServletRequest request, ModelMap model) throws IOException {
        Map<String, Object> insertMap = new HashMap<String, Object>();
        insertMap.put("byt", file.getBytes());
        insertMap.put("fileName", file.getOriginalFilename());

        int flag = fileUpAndDownMapper.saveFileInfo(insertMap);
        if(flag > 0)
            model.addAttribute("upload.message", "success");
        else
            model.addAttribute("upload.message", "failure");
        return "/core/param/businessparam/uploadResult";
    }
}

FileUpAndDownMapper.xml

 <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
    namespace="com.xx.persistence.FileUpAndDownMapper">

    <resultMap id="fileBean" type="com.xx.web.FileUpAndDown">
        <id column="ID" property="id" jdbcType="INTEGER" />
        <result column="FILENAME" property="fileName" jdbcType="VARCHAR" />
        <result column="TESTA" property="testa" javaType="byte[]" jdbcType="BLOB" typeHandler="org.apache.ibatis.type.BlobTypeHandler" />
        <result column="FILESTREAM" property="fileStream" javaType="byte[]" jdbcType="BLOB" typeHandler="org.apache.ibatis.type.BlobTypeHandler" />
    </resultMap>  

    <insert id="saveFileInfo" parameterType="java.util.HashMap">
    INSERT INTO BLOBTEST(FILENAME, FILESTREAM)
    VALUES(#{fileName}, #{byt, javaType=byte[], jdbcType=BLOB, typeHandler=org.apache.ibatis.type.BlobTypeHandler})
    </insert>

    <select id="getFileByPk" resultMap="fileBean" parameterType="int">
      SELECT * FROM BLOBTEST WHERE ID=${value}
     </select>
</mapper>

xml加的

 <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/>

FileUpAndDown.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<html>
<head>
<title>using commons Upload to upload file</title>
</head>
<script type="text/javascript">
function downFile(){
    var fileId = document.getElementById("fileId").value;
    location.href="fileDownload?fileId=" + fileId;
}
</script>
<style>
* {
    font-family: "宋体";
    font-size: 14px
}
</style>
<body>
    <p align="center">文件上传下载</p>
    <form id="form1" name="form1" method="post" action="fileUpload" enctype="multipart/form-data">
        <table border="0" align="center">
            <tr>
                <td>上传文件:</td>
                <td><input name="file" type="file" size="20"></td>
            </tr>
            <tr>
                <td></td>
                <td><input type="submit" value="提交"> <input type="reset" name="reset" value="重置"></td>
            </tr>
        </table>
    </form>
    <div align="center">
    <input type="text" id="fileId"><input type="button" value="依据Id下载文件" onclick="javascript:downFile()">
    </div>
</body>
</html>

fileUpload.jsp

 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<title>uploadResult</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
    <a href="fileManagePage">上传文件</a> ${requestScope['upload.message'] }
</body>
</html>

报错:fileUpAndDownMapper cannot be resolved

  • 写回答

10条回答 默认 最新

  • 兜兜里有毒 2018-05-16 15:15
    关注

    你这个fileUpAnddownMapper是哪个来的?这个根本就没定义,编辑器肯定报错嘛,如果是类的话,请注意大小写,

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog