Вот код метода:
@Override
public void accountImport(String fileName, AccountDto accountDto) {
try(FileWriter writer = new FileWriter(fileName, false))
{
Integer id = accountDto.getId();
String stId= id.toString();
Long number = accountDto.getNumber();
String stNumber = number.toString();
String date = accountDto.getDate();
String beneficiary = accountDto.getBeneficiary();
String comment = accountDto.getComment();
Long amount = accountDto.getAmount();
String stAmount = amount.toString();
String currency = accountDto.getCurrency();
String finall = stId+","+stNumber+","+date+","+beneficiary+","+comment+","+stAmount+","+currency;
for (int i = 0; i < finall.length(); i++)
writer.write(finall.charAt(i));
} catch (IOException e) {
throw new ValidateException("ERROR");
}
}
Вот код контроллера:
@PostMapping("/import")
public ResponseEntity importAccount(@RequestParam(name = "fileName",required = false) String fileName, @RequestBody AccountDto accountDto){
accountServiceImport.accountImport(fileName,accountDto);
return new ResponseEntity(HttpStatus.OK);
}
Вот запрос в Postman:
{
"fileName": "C:\\Users\\Admin\\Documents\\task\\text.csv",
"account":{
"id": 0,
"number": 84822,
"date": "2022-04-06 22:58 ",
"beneficiary": "Bob",
"comment": "For",
"amount": 8482200,
"currency": "USA"
}
}

