2024.5.23(第二阶段冲刺第九天)
所学时间:3小时
代码行数:71行
博客园数:1篇
所学知识:
1.我昨天的成就:写完了前端springboot接收的基本代码
2.遇到什么困难:前端springboot接收出现的问题
3.今天的任务:继续写后端springboot代码,接收前端传来的代码
4.今天所敲的代码:
public static String saveToFile(File fileToSave, File destinationDirectory) throws IOException {
// 创建目标文件夹(如果不存在)
if (!destinationDirectory.exists()) {
destinationDirectory.mkdirs();
}
// 创建目标文件
File destinationFile = new File(destinationDirectory, fileToSave.getName());
// 使用文件输入流读取源文件,文件输出流写入目标文件
try (FileInputStream fis = new FileInputStream(fileToSave);
FileOutputStream fos = new FileOutputStream(destinationFile)) {
byte[] buffer = new byte[1024];
int length;
while ((length = fis.read(buffer)) > 0) {
fos.write(buffer, 0, length);
}
}
return destinationFile.getAbsolutePath();
}
@RestController
@RequestMapping("/JuBao")
@CrossOrigin//支持跨域
public class JuBaoController {
@Autowired
GetFishService getFishService;
@PostMapping
public void JuBao(@RequestBody Result<Jubao> jubao) throws IOException {
getFishService.tianJiaJuBao(jubao.getResult());
}
@GetMapping("/getJuBao")
public Result<List<Jubao>> getJuBao(){
Result<List<Jubao>> result = new Result<>();
result.setResult(getFishService.getJuBao());
return result;
}
}