This commit is contained in:
parent
2897173672
commit
e17e4bae53
|
|
@ -7,8 +7,11 @@ import live.tomey.api.express.entity.News;
|
||||||
import live.tomey.api.express.service.NewsService;
|
import live.tomey.api.express.service.NewsService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -22,6 +25,39 @@ public class NewsController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private NewsService newsService;
|
private NewsService newsService;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@PassToken
|
||||||
|
@PostMapping("/addnews")
|
||||||
|
private Result<List<News>> addNews(@RequestParam("file")MultipartFile file,@RequestParam("title")String title,@RequestParam("content") String content){
|
||||||
|
try {
|
||||||
|
if (file.isEmpty()){
|
||||||
|
return new Result<>(false,-1,"新增失败,请选择文件!");
|
||||||
|
}
|
||||||
|
String fileName = file.getOriginalFilename();
|
||||||
|
// String filePath = "F:\\Work\\file\\";
|
||||||
|
String filePath = "/www/wwwroot/express/file/";
|
||||||
|
String url = "http://47.96.37.195:8084/";
|
||||||
|
//确保有这个文件目录才能使用
|
||||||
|
File dect = new File(filePath,fileName);
|
||||||
|
News news = new News();
|
||||||
|
try {
|
||||||
|
file.transferTo(dect);
|
||||||
|
news.setTitle(title);
|
||||||
|
news.setContent(content);
|
||||||
|
news.setImgUrl(url+fileName);
|
||||||
|
newsService.addNews(news);
|
||||||
|
}catch (IOException e){
|
||||||
|
return new Result<>(false, -1, e.getMessage()+"文件错误");
|
||||||
|
}
|
||||||
|
return new Result<>(true,1,url+fileName);
|
||||||
|
}catch (RuntimeException e){
|
||||||
|
System.out.println(e.getMessage());
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
// return new Result<>(false, -1, e.getMessage()+"系统错误");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@PassToken
|
@PassToken
|
||||||
@PostMapping
|
@PostMapping
|
||||||
private Result<List<News>> getList(@RequestBody News news) {
|
private Result<List<News>> getList(@RequestBody News news) {
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ public class AuthenticationInterceptor extends HandlerInterceptorAdapter {
|
||||||
if (!(handler instanceof HandlerMethod)) {
|
if (!(handler instanceof HandlerMethod)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
System.out.println(((HandlerMethod) handler).getMethod().getName());
|
||||||
HandlerMethod handlerMethod = (HandlerMethod) handler;
|
HandlerMethod handlerMethod = (HandlerMethod) handler;
|
||||||
Method method = handlerMethod.getMethod();
|
Method method = handlerMethod.getMethod();
|
||||||
//检查是否有passtoken注释,有则跳过认证
|
//检查是否有passtoken注释,有则跳过认证
|
||||||
|
|
@ -51,7 +52,7 @@ public class AuthenticationInterceptor extends HandlerInterceptorAdapter {
|
||||||
JSONObject res = new JSONObject();
|
JSONObject res = new JSONObject();
|
||||||
if (token == null) {
|
if (token == null) {
|
||||||
res.put("success", false);
|
res.put("success", false);
|
||||||
res.put("msg", "缺少必要参数");
|
res.put("msg", "缺少token参数");
|
||||||
res.put("errorCode", -1);
|
res.put("errorCode", -1);
|
||||||
response.getWriter().write(res.toString());
|
response.getWriter().write(res.toString());
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -24,9 +24,9 @@ spring.servlet.multipart.maxRequestSize=200MB
|
||||||
# 数据库dataSource
|
# 数据库dataSource
|
||||||
jdbc.driver=8zQIdS8RzOBmd4qRctgYdYM/fdvrjnIJHyQH1bD/jNs=
|
jdbc.driver=8zQIdS8RzOBmd4qRctgYdYM/fdvrjnIJHyQH1bD/jNs=
|
||||||
#服务器本地127.0.0.1
|
#服务器本地127.0.0.1
|
||||||
jdbc.url=jdbc:mysql://127.0.0.1:3306/mall?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true
|
jdbc.urls=jdbc:mysql://127.0.0.1:3306/mall?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true
|
||||||
#azure
|
#azure
|
||||||
jdbc.urls=jdbc:mysql://40.83.126.15:3306/mall?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true
|
jdbc.url=jdbc:mysql://13.75.92.40:3306/mall?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true
|
||||||
#服务器ip
|
#服务器ip
|
||||||
jdbc.username=mall
|
jdbc.username=mall
|
||||||
jdbc.password=dr4ap4dbnyCMZTcr
|
jdbc.password=dr4ap4dbnyCMZTcr
|
||||||
|
|
@ -36,6 +36,15 @@ mybatis_config_file=mybatis-config.xml
|
||||||
mapper_path=/mapper/**.xml
|
mapper_path=/mapper/**.xml
|
||||||
typealias_package=live.tomey.api.express.entity
|
typealias_package=live.tomey.api.express.entity
|
||||||
|
|
||||||
|
# 上传文件总的最大值
|
||||||
|
spring.servlet.multipart.max-request-size=10MB
|
||||||
|
# 单个文件的最大值
|
||||||
|
spring.servlet.multipart.max-file-size=10MB
|
||||||
|
|
||||||
|
## jsp
|
||||||
|
spring.mvc.view.prefix=/WEB-INF/jsp/
|
||||||
|
spring.mvc.view.suffix=.jsp
|
||||||
|
|
||||||
#Redis配置
|
#Redis配置
|
||||||
redis.hostname=34.92.103.14
|
redis.hostname=34.92.103.14
|
||||||
redis.port=6379
|
redis.port=6379
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue