Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
guns-vip
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
chenjunxiong
guns-vip
Commits
5e512023
Commit
5e512023
authored
Jun 28, 2018
by
stylefeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
解决上传头像问题
parent
40369b81
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
5 deletions
+18
-5
guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/KaptchaController.java
+2
-2
guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/UserMgrController.java
+3
-2
guns-core/src/main/java/com/stylefeng/guns/core/util/ToolUtil.java
+13
-1
No files found.
guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/KaptchaController.java
View file @
5e512023
...
...
@@ -98,11 +98,11 @@ public class KaptchaController {
*/
@RequestMapping
(
"/{pictureId}"
)
public
void
renderPicture
(
@PathVariable
(
"pictureId"
)
String
pictureId
,
HttpServletResponse
response
)
{
String
path
=
gunsProperties
.
getFileUploadPath
()
+
pictureId
+
".jpg"
;
String
path
=
gunsProperties
.
getFileUploadPath
()
+
pictureId
;
try
{
byte
[]
bytes
=
FileUtil
.
toByteArray
(
path
);
response
.
getOutputStream
().
write
(
bytes
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
//如果找不到图片就返回一个默认图片
try
{
response
.
sendRedirect
(
"/static/img/girl.gif"
);
...
...
guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/UserMgrController.java
View file @
5e512023
...
...
@@ -337,12 +337,13 @@ public class UserMgrController extends BaseController {
}
/**
* 上传图片
(上传到项目的webapp/static/img)
* 上传图片
*/
@RequestMapping
(
method
=
RequestMethod
.
POST
,
path
=
"/upload"
)
@ResponseBody
public
String
upload
(
@RequestPart
(
"file"
)
MultipartFile
picture
)
{
String
pictureName
=
UUID
.
randomUUID
().
toString
()
+
".jpg"
;
String
pictureName
=
UUID
.
randomUUID
().
toString
()
+
"."
+
ToolUtil
.
getFileSuffix
(
picture
.
getOriginalFilename
());
try
{
String
fileSavePath
=
gunsProperties
.
getFileUploadPath
();
picture
.
transferTo
(
new
File
(
fileSavePath
+
pictureName
));
...
...
guns-core/src/main/java/com/stylefeng/guns/core/util/ToolUtil.java
View file @
5e512023
...
...
@@ -408,7 +408,7 @@ public class ToolUtil {
* map的key转为小写
*
* @param map
* @return Map<String
,
Object>
* @return Map<String
,
Object>
*/
public
static
Map
<
String
,
Object
>
caseInsensitiveMap
(
Map
<
String
,
Object
>
map
)
{
Map
<
String
,
Object
>
tempMap
=
new
HashMap
<>();
...
...
@@ -568,4 +568,15 @@ public class ToolUtil {
throw
new
RuntimeException
(
e
);
}
}
/**
* 获取文件后缀名 不包含点
*/
public
static
String
getFileSuffix
(
String
fileWholeName
)
{
if
(
ToolUtil
.
isEmpty
(
fileWholeName
))
{
return
"none"
;
}
int
lastIndexOf
=
fileWholeName
.
lastIndexOf
(
"."
);
return
fileWholeName
.
substring
(
lastIndexOf
+
1
);
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment