Java中上传文件操作

package com.bootdo.nsmp.domain;

import java.io.Serializable;

public class Material implements Serializable{
    private static final long serialVersionUID = 1L;
    //主键Id
    private Long id;
    //系统拓扑结构说明
    private  Integer structure;
    //对应的文件
    private  String struFile;
    //对应的文件路径
    private  String struFileUrl;
    //系统安全组织架构
    private  Integer safe;
    //对应的文件
    private  String safeFile;
    //对应的文件路径
    private  String safeFileUrl;
    //系统安全保护设施设计实施方案
    private  Integer protect;
    //对应的文件
    private  String proFile;
    //对应的文件路径
    private  String proFileUrl;
    //系统使用的安全产品清单
    private  Integer list;
    //对应的文件
    private  String listFile;
    //对应的文件路径
    private  String listFileUrl;
    //系统等级测试报告
    private  Integer clazz;
    //对应的文件
    private  String clazzFile;
    //对应的文件路径
    private  String clazzFileUrl;
    //专家评审情况
    private  Integer judge;
    //对用的文件
    private  String judgeFile;
    //对用的文件路径
    private  String judgeFileUrl;
    //上级主管部门评审意见
    private  Integer gover;
    //对应的文件
    private  String goverFile;
    //对应的文件
    private  String goverFileUrl;


}

原理:在Java中,数据库使用的是MySQL数据库,在存储的时候,分别存储的是文件的名称和路径,所以我们在创建实体类的时候,实际上创建的是文件名和路径,在创建数据库的时候,将文件名和路径对应的字段分别创建,在存储的时候,分别存储文件名和路径。实际上文件名和文件的路径是存储在数据库中的,但是真正的文件时存储在服务器上的。

文件具体怎么调用,等到我做到哪一步了会再写出来。(这里只是实体类的写法)

以下是mapper.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.bootdo.nsmp.dao.MaterialDao">

	<select id="list" resultType="com.bootdo.nsmp.domain.Material">
		select * from material
		<if test="offset != null and limit != null">
			limit ${offset}, ${limit}
		</if>
	</select>

	<select id="count" resultType="int">
		select count(*) from material
	</select>

	<insert id="save" parameterType="com.bootdo.nsmp.domain.Material"
			useGeneratedKeys="true" keyProperty="id">
		insert into material
		(
		`structure`,
		`struFile`,
		`struFileUrl`,
		`safe`,
		`safeFile`,
		`safeFileUrl`,
		`protect`,
		`proFile`,
		`proFileUrl`,
		`list`,
		`listFile`,
		`listFileUrl`,
		`clazz`,
		`clazzFile`,
		`clazzFileUrl`,
		`judge`,
		`judgeFile`,
		`judgeFileUrl`,
		`gover`,
		`goverFile`,
		`goverFileUrl`
		)
		values
		(
		#{structure},
		#{struFile},
		#{struFileUrl},
		#{safe},
		#{safeFile},
		#{safeFileUrl},
		#{protect},
		#{proFile},
		#{proFileUrl},
		#{list},
		#{listFile},
		#{listFileUrl},
		#{clazz},
		#{clazzFile},
		#{clazzFileUrl},
		#{judge},
		#{judgeFile},
		#{judgeFileUrl},
		#{gover},
		#{goverFile},
		#{goverFileUrl}

		)
	</insert>

</mapper>

创建数据库:

select * from material;

CREATE TABLE material
(
		id BIGINT(11) not null PRIMARY KEY,
		structure int(30),
		struFile VARCHAR(50),
		struFileUrl VARCHAR(50),
		safe int(30),
		safeFile VARCHAR(50),
		safeFileUrl VARCHAR(50),
		protect int(30),
		proFile VARCHAR(50),
		proFileUrl VARCHAR(50),
		list int(30),
		listFile VARCHAR(50),
		listFileUrl VARCHAR(50),
		clazz int(30),
		clazzFile VARCHAR(50),
		clazzFileUrl VARCHAR(50),
		judge int(30),
		judgeFile VARCHAR(50),
		judgeFileUrl VARCHAR(50),
		gover int(30),
		goverFile VARCHAR(50),
		goverFileUrl VARCHAR(50)
)

 前端设置:

 <tr>
                           <th>
                               <em class="gg-star">*</em>
                               <span>上级主管部门审批意见</span>
                           </th>
                           <td>
                               <input type="radio" name="gover" value="有">有
                               <input type="radio" name="gover" value="无">无
                           </td>
                           <td>
                               <div class="form-group">
                                   <label class="col-sm-3 control-label">附件:</label>
                                   <div class="col-sm-8">
                                       <input id="files7" name="goverFile" class="form-control" type="file">
                                   </div>
                               </div>
                           </td>
                       </tr>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值