苍穹外卖--新增菜品-文件上传功能实现
This commit is contained in:
@@ -58,13 +58,13 @@ public class AutoFillAspect {
|
||||
Method setUpdateUser = arg.getClass().getDeclaredMethod(AutoFillConstant.SET_UPDATE_USER, Long.class);
|
||||
setUpdateUser.invoke(arg,currentId);
|
||||
|
||||
} else {
|
||||
}
|
||||
//update
|
||||
Method setUpdateTime = arg.getClass().getDeclaredMethod(AutoFillConstant.SET_UPDATE_TIME, LocalDateTime.class);
|
||||
setUpdateTime.invoke(arg,now);
|
||||
Method setUpdateUser = arg.getClass().getDeclaredMethod(AutoFillConstant.SET_UPDATE_USER, Long.class);
|
||||
setUpdateUser.invoke(arg,currentId);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.sky.config;
|
||||
|
||||
import com.sky.properties.InmindAliOSSProperties;
|
||||
import com.sky.utils.InmindAliOSSUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* 为sky-server模块,注册OSS工具类对象到sprong容器中
|
||||
*/
|
||||
@Configuration
|
||||
@Slf4j
|
||||
public class OssConfiguration {
|
||||
|
||||
@Bean
|
||||
public InmindAliOSSUtils inmindAliOSSUtils(InmindAliOSSProperties aliOSSProperties){
|
||||
log.info("开始创建阿里云文件上传工具类对象到sprong容器中...,{}",aliOSSProperties);
|
||||
return new InmindAliOSSUtils(aliOSSProperties);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.sky.controller.admin;
|
||||
|
||||
import com.aliyuncs.exceptions.ClientException;
|
||||
import com.sky.result.Result;
|
||||
import com.sky.utils.InmindAliOSSUtils;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@RestController
|
||||
@Slf4j
|
||||
@Api(tags = "通用接口")
|
||||
@RequestMapping("/admin/common")
|
||||
public class CommonController {
|
||||
|
||||
@Autowired
|
||||
private InmindAliOSSUtils inmindAliOSSUtils;
|
||||
|
||||
|
||||
@PostMapping("/upload")
|
||||
@ApiOperation("文件上传")
|
||||
public Result<String> upload(MultipartFile file) {
|
||||
log.info("文件上传:{}",file);
|
||||
String uploadUrl = null;
|
||||
try {
|
||||
uploadUrl = inmindAliOSSUtils.upload(file);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (ClientException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return Result.success(uploadUrl);
|
||||
}
|
||||
}
|
||||
@@ -6,3 +6,7 @@ sky:
|
||||
database: sky_take_out2
|
||||
username: root
|
||||
password: 1234
|
||||
alioss:
|
||||
endpoint: https://oss-cn-shanghai.aliyuncs.com
|
||||
bucket-name: inmind-test
|
||||
region: cn-shanghai
|
||||
|
||||
@@ -3,7 +3,7 @@ server:
|
||||
|
||||
spring:
|
||||
profiles:
|
||||
active: dev
|
||||
active: dev #程序的运行环境:开发环境
|
||||
main:
|
||||
allow-circular-references: true
|
||||
datasource:
|
||||
@@ -37,3 +37,7 @@ sky:
|
||||
admin-ttl: 72000000
|
||||
# 设置前端传递过来的令牌名称
|
||||
admin-token-name: token
|
||||
alioss:
|
||||
endpoint: ${sky.alioss.endpoint}
|
||||
bucket-name: ${sky.alioss.bucket-name}
|
||||
region: ${sky.alioss.region}
|
||||
|
||||
Reference in New Issue
Block a user