springboot 使用总结-持续更新……

Posted myhanghang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了springboot 使用总结-持续更新……相关的知识,希望对你有一定的参考价值。

1, springboot 文件上传到某个位置,使用虚拟位置进行访问

import org.springboot.sample.interceptor.MyInterceptor1;
import org.springboot.sample.interceptor.MyInterceptor2;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class MyWebAppConfigurer extends WebMvcConfigurerAdapter {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/myres/**").addResourceLocations("classpath:/myres/");
registry.addResourceHandler("/myimgs/aaa/**").addResourceLocations("file:H:/myimgs/");
super.addResourceHandlers(registry); } }

2,springboot  liunx 后台启动,并且指定日志输出位置。

nohup java -jar guns-admin-1.0.0.jar > catalina.out  2>&1 &

3,springboot上传文件

 /**
     * 上传图片
     */
    @RequestMapping(method = RequestMethod.POST, path = "/upload")
    @ResponseBody
    public JSONObject upload(@RequestPart("image") MultipartFile picture,HttpServletRequest request) {

        String pictureName = UUID.randomUUID().toString() + "." + ToolUtil.getFileSuffix(picture.getOriginalFilename());
        try {
            String fileSavePath = "ssssssss";
            picture.transferTo(new File(fileSavePath + pictureName));
        } catch (Exception e) {
            e.printStackTrace();
            throw new GunsException(BizExceptionEnum.UPLOAD_ERROR);
        }
        JSONObject json  = new JSONObject();
        json.put("errno", 0);
        JSONArray data = new JSONArray();
        data.add("/static/images/"+pictureName);
        json.put("data", data);
        return json;
    }

 


以上是关于springboot 使用总结-持续更新……的主要内容,如果未能解决你的问题,请参考以下文章

Idea几点使用总结(持续更新)

springboot复习(黑马)(持续更新)

3月4日作业总结 持续更新

回归 | js实用代码片段的封装与总结(持续更新中...)

Spring Boot 持续更新中...

jenkins持续集成springboot