src/main/java/com/yuanlrc/base/controller/common/PhotoController.java
(完整代码) 1KBpackage com.yuanlrc.base.controller.common;
/**
* 图片统一查看控制器
*/
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
@RequestMapping("photo")
@Controller
public class PhotoController {
@Autowired
private ResourceLoader resourceLoader;
@Value("${ylrc.upload.photo.path}")
private String uploadPhotoPath;//文件保存位置
/**
* 系统统一的图片查看方法
* @param filename
* @return
*/
@RequestMapping(value="/view")
@ResponseBody
public ResponseEntity<?> viewPhoto(@RequestParam(name="filename",required=true)String filename){
Resource resource = resourceLoader.getResource("file:" + uploadPhotoPath + filename);
try {
return ResponseEntity.ok(resource);
} catch (Exception e) {
return ResponseEntity.notFound().build();
}
}
}
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。