java热部署实现shiro,记springboot上传文件的过程 前后端分离 shiro

@[理想](记springboot上传文件的过程 前后端分离 shiro)

记springboot上传文件的过程 前后端分离 shiro

最近在用vue+springboot在前后端分离的模式下做项目,在遇到上传文件的时候发生了一些问题。

1.后端代码怎么写(如下)

public Object InboxInfoUpload(InboxInfo inboxInfo, @RequestParam("file") MultipartFile file, HttpServletRequest request) throws IOException {

if (file.isEmpty()) {

return "空文件";

}

// 获取文件名

String fileName = file.getOriginalFilename();

String suffixName = fileName.substring(fileName.lastIndexOf("."));

fileName = UUID.randomUUID() + suffixName;

String filePath = "//C://Users//lx//IdeaProjects//anonymous//src//main//resources//static//attach//";

File dest = new File(filePath+fileName);

// // 检测是否存在目录

if (!dest.getParentFile().exists()) {

dest.getParentFile().mkdirs();

}

try {

file.transferTo(dest);

} catch (Exception e) {

e.printStackTrace();

}

return fileName;

}

注意:返回时尽量返回fileName。

2.shiro的问题

由于图片在static中存储,在shiro的内置过滤器中需要开放。

333fb143f743254ccf0f6f4d550535bc.png

Map filterMao = new LinkedHashMap();

filterMao.put("/static/**", "anon");

filterMao.put("/attach/**","anon");

filterMao.put("/image/**","anon");

filterMao.put("/inboxinfo/add","anon");

filterMao.put("/inboxinfo/upload","anon");

filterMao.put("/login", "anon");

filterMao.put("/logout","user");

filterMao.put("/**", "authc");

shiroFilterFactoryBean.setFilterChainDefinitionMap(filterMao);

// 如果不设置默认会自动寻找Web工程根目录下的"/login.jsp"页面

shiroFilterFactoryBean.setLoginUrl("/login");

// 登录成功后要跳转的链接

shiroFilterFactoryBean.setSuccessUrl("/index");

return shiroFilterFactoryBean;

}

特别需要注意的是:内置过滤器不仅仅要开放static,还要开放static下面的其他文件夹才可以。

3.关于热部署的问题

静态资源修改后需要重新启动项目才可以生效,这里记录一个不需要重启的办法。

e0359929d4df32f6ea31992626e521ef.png

然后打开file→settings→Compiler→勾选红圈内容→Apply

4dc47b320721314866f2d00358f43334.png

然后快捷键:“Shift+Ctrl+Alt+/”,选择 “Registry” ,选中打勾 “compiler.automake.allow.when.app.running”

4b588c29b1fea2165b50923469f71ce1.png

67caa3569f267f7a052f9c9c77b0a6c2.png

本文地址:https://blog.csdn.net/Javafor1997/article/details/110876648

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值