批量上传图片伪代码
This commit is contained in:
parent
2779278a41
commit
4a162a4eda
|
@ -7,6 +7,7 @@ import com.dite.znpt.domain.vo.ImageResp;
|
|||
import com.dite.znpt.mapper.ImageMapper;
|
||||
import com.dite.znpt.service.ImageService;
|
||||
import com.dite.znpt.util.PageUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -15,6 +16,7 @@ import java.util.List;
|
|||
* @date 2025/4/24/周四 13:23
|
||||
* @description
|
||||
*/
|
||||
@Service
|
||||
public class ImageServiceImpl extends ServiceImpl<ImageMapper, ImageEntity> implements ImageService {
|
||||
@Override
|
||||
public List<ImageResp> selectList(ImageListReq req) {
|
||||
|
|
|
@ -5,16 +5,26 @@ import com.dite.znpt.domain.PageResult;
|
|||
import com.dite.znpt.domain.vo.ImageListReq;
|
||||
import com.dite.znpt.domain.vo.ImageResp;
|
||||
import com.dite.znpt.service.ImageService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Bear.G
|
||||
* @date 2025/4/24/周四 12:46
|
||||
* @description
|
||||
*/
|
||||
@Api(tags = "图像信息")
|
||||
@RestController
|
||||
@RequestMapping("/image")
|
||||
public class ImageController {
|
||||
|
||||
@Resource
|
||||
|
@ -26,4 +36,22 @@ public class ImageController {
|
|||
return PageResult.ok(imageService.selectList(req));
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "批量上传图像", httpMethod = "POST")
|
||||
@PostMapping("/upload-batch/{departId}")
|
||||
public List uploadBatch(@PathVariable String departId, @RequestParam("files") MultipartFile[] files) {
|
||||
for (MultipartFile file : files) {
|
||||
if (!file.isEmpty()) {
|
||||
try {
|
||||
byte[] bytes = file.getBytes();
|
||||
java.nio.file.Path path = Paths.get("G:\\Image/" + file.getOriginalFilename());
|
||||
Files.write(path, bytes);
|
||||
System.out.println("Uploaded: " + file.getOriginalFilename());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue