添加文件上传测试

This commit is contained in:
谢洪龙 2017-07-14 17:51:57 +08:00
parent 67afdcc372
commit 1e7618c135
7 changed files with 56 additions and 11 deletions

View File

@ -76,6 +76,12 @@
<version>0.9.1.2</version> <version>0.9.1.2</version>
<type>jar</type> <type>jar</type>
</dependency> </dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.2</version>
<type>jar</type>
</dependency>
<dependency> <dependency>
<groupId>javax</groupId> <groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId> <artifactId>javaee-web-api</artifactId>

View File

@ -5,11 +5,12 @@
*/ */
package com.ifish.config; package com.ifish.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScan.Filter; import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType; import org.springframework.context.annotation.FilterType;
import org.springframework.context.annotation.Import; import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.EnableWebMvc;
/** /**
@ -23,4 +24,16 @@ import org.springframework.web.servlet.config.annotation.EnableWebMvc;
@Filter(type = FilterType.ANNOTATION, value = EnableWebMvc.class)}) @Filter(type = FilterType.ANNOTATION, value = EnableWebMvc.class)})
public class RootConfig { public class RootConfig {
/**
* 文件上传
*
* @return
*/
@Bean
public CommonsMultipartResolver multipartResolver() {
CommonsMultipartResolver commonsMultipartResolver = new CommonsMultipartResolver();
commonsMultipartResolver.setMaxUploadSize(10485760);
return commonsMultipartResolver;
}
} }

View File

@ -5,9 +5,13 @@
*/ */
package com.ifish.controller; package com.ifish.controller;
import com.ifish.helper.FastDFSClientI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
/** /**
* *
@ -20,4 +24,15 @@ public class Index {
public String index() { public String index() {
return "index"; //返回的视图名为index指向/WEB-INF/Views/index.jsp return "index"; //返回的视图名为index指向/WEB-INF/Views/index.jsp
} }
@Autowired
private FastDFSClientI fastDFSClientI;
@RequestMapping(value = "/test", method = RequestMethod.POST)
@ResponseBody
public String test(MultipartFile file) {
String filstring = fastDFSClientI.uploadFileToFastDFS(file);
return "abc";
}
} }

View File

@ -36,6 +36,13 @@ public class Login {
return userHelperI.login(user); return userHelperI.login(user);
} }
/**
* 发送手机验证码
*
* @param sendType
* @param phoneNumber
* @return
*/
@RequestMapping("/getSecurityCode.do") @RequestMapping("/getSecurityCode.do")
public Object getSecurityCode(String sendType, String phoneNumber) { public Object getSecurityCode(String sendType, String phoneNumber) {
try { try {
@ -45,6 +52,12 @@ public class Login {
return IfishUtil.returnJson(ResultEnum.fail101.getKey(), ""); return IfishUtil.returnJson(ResultEnum.fail101.getKey(), "");
} }
/**
* 手机注册
*
* @param user
* @return
*/
@RequestMapping(value = "/registerByMobile", method = RequestMethod.GET) @RequestMapping(value = "/registerByMobile", method = RequestMethod.GET)
public Object registerByMobile(Tbl_User user) { public Object registerByMobile(Tbl_User user) {
return userHelperI.registerByMobile(user); return userHelperI.registerByMobile(user);

View File

@ -131,13 +131,7 @@ public class FastDFSClient implements FastDFSClientI {
} else { } else {
return ""; return "";
} }
//本地返回测试环境fastfds,线上返回正式服务器部署的fastfds
if (IfishUtil.IsWinOrUnix()) {
return IfishFilePath.fastDFS_url_app + url;
} else {
return IfishFilePath.link_img_head + url; return IfishFilePath.link_img_head + url;
}
} catch (Exception e) { } catch (Exception e) {
return ""; return "";
} }

View File

@ -27,9 +27,9 @@ fastDFS_url_app=http://app.ifish7.com/
#\u672c\u5730 #\u672c\u5730
#link_img_head=http://192.168.61.128:81/ #link_img_head=http://192.168.61.128:81/
#\u6d4b\u8bd5\u73af\u5883 #\u6d4b\u8bd5\u73af\u5883
#link_img_head=https://app.zhangxinyanv5.top/ link_img_head=https://app.zhangxinyanv5.top/
#\u6b63\u5f0f\u73af\u5883 #\u6b63\u5f0f\u73af\u5883
link_img_head=https://app.ifish7.com/ #link_img_head=https://app.ifish7.com/
#\u56fe\u7247\u683c\u5f0f\u9a8c\u8bc1 #\u56fe\u7247\u683c\u5f0f\u9a8c\u8bc1
check_style=GIF,PNG,BMP,JPG,JPEG check_style=GIF,PNG,BMP,JPG,JPEG
#\u662f\u5426\u5f00\u53d1\u6a21\u5f0f\uff0cfalse\u5219\u4ee3\u8868\u8981\u53d1\u5e03\u5230\u6d4b\u8bd5\u6216\u8005\u6b63\u5f0f\u73af\u5883\uff0c\u4f1a\u8fdb\u884c\u5168\u5c40\u5934\u90e8\u9a8c\u8bc1\uff0ctrue\u4ee3\u8868\u5728\u672c\u5730\u8fdb\u884c\u4ee3\u7801\u7f16\u5199\uff0c\u4e0d\u4f1a\u8fdb\u884c\u9a8c\u8bc1 #\u662f\u5426\u5f00\u53d1\u6a21\u5f0f\uff0cfalse\u5219\u4ee3\u8868\u8981\u53d1\u5e03\u5230\u6d4b\u8bd5\u6216\u8005\u6b63\u5f0f\u73af\u5883\uff0c\u4f1a\u8fdb\u884c\u5168\u5c40\u5934\u90e8\u9a8c\u8bc1\uff0ctrue\u4ee3\u8868\u5728\u672c\u5730\u8fdb\u884c\u4ee3\u7801\u7f16\u5199\uff0c\u4e0d\u4f1a\u8fdb\u884c\u9a8c\u8bc1

View File

@ -9,5 +9,9 @@
</head> </head>
<body> <body>
<h1 style="text-align: center">访问正常!</h1> <h1 style="text-align: center">访问正常!</h1>
<form action="/api/test" method="post" enctype="multipart/form-data">
<input type="file" name="file" >
<input type="submit" value="提交">
</form>
</body> </body>
</html> </html>