qq_24932993 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 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B
  • ¥15 想问一下stata17中这段代码哪里有问题呀
  • ¥15 flink cdc无法实时同步mysql数据
  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决