使用Ext 3.4.x
版本实现上传.txt
文件(文件内为id值),删除table_a
对应记录
要求:
上传一个txt文件,根据文件内的id删除对应的记录。
需求分析:
- 使用
Ext 3.4.0
上传文件; Java
解析前端上传的文件,得到待删除List<Long>
;- 使用
jdbctemplate
批量删除接口,完成删除操作。
js 页面(表单代码)
页面出现连个按钮
1 | <style type=text/css> |
文件类型不支持,需要引用fileuploadfield
组件
css
文件内容
1 | .upload-icon { |
js
文件内容
以下 javascript
代码的样式可以自己修改,主要内容是 xtype : 'fileuploadfield'、xtype:'button'
。同时,提交方式也可以自行替换(Ajax等)
1 | Ext.onReady(function () { |
文件上传 Java
后端代码
Controller —— 获取传递的参数,获取文件
1 | import org.springframework.web.multipart.MultipartFile; |
Service —— 将 file
转为 list
1 | import org.springframework.web.multipart.MultipartFile; |
注:
当前方法读取的文件如下图所示
Repository 批量删除的方法 —— jdbctemplae
方式
1 | import org.springframework.jdbc.core.BatchPreparedStatementSetter; |
常见异常
不支持文件上传
1 | org.springframework.web.bind.MissingServletRequestParameterException: Required MultipartFile parameter 'hcodeFile' is not present |
- 方法: 在
applicationContext.xml
文件中实例化bean
,添加如下内容
1 | <!-- 支持文件上传 --> |