I mean, this is what i have in my code:
@GetMapping("/get/player/{csvName}")
public void loadPlayers(@PathVariable String csvName) {
/*Irrelevant code here*/
}
This works just because the csv file is in the root of my project.
Is there any way to set the relative path of the csv file on the url?
////////////////////////////////////////////////////EDIT///////////////////////////////////////////////////////
Here is the code of the class:
@RestController
@RequestMapping("/csv")
public class CsvController {
private static final Logger log = LoggerFactory.getLogger(FutbolApplication.class);
@Autowired
private PlayerRepository playerRepository;
@Autowired
private TeamRepository teamRepository;
@Autowired
private MembershipRepository memberRepository;
@GetMapping("/get/player/{csvName}")
public void loadPlayers(@PathVariable String csvName) {
CSVReader reader;
try {
reader = new CSVReaderBuilder(new FileReader(csvName))
.withSkipLines(1).build();
String[] values;
int i;
int count=0;
while ((values = reader.readNext()) != null) {
count++;
i=0;
try {
Player player = new Player(values[i++],values[i++],values[i++],Date.valueOf(values[i++]));
System.out.println(player.getName() + "//" + player.getSurname() + "//" + player.getPosition()
+ "//" + player.getBirthDate());
playerRepository.save(player);
}catch (Exception e) {
log.error("ERROR INTENTANDO ASIGNAR LOS DATOS AL JUGADOR "+(count));
}
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (CsvValidationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
What I can to, is to insert the path of the csv instead of just the name.
At the moment my project's structure is:
>project
>src
>main
>test
>.Settings
>mycsvfile.csv
that's why i can just type "mycsvfile.csv" in the url and it works
But this is what i'd like to get:
>project
>src
>main
>test
>.Settings
>csvs
>mycsvfile.csv
And get it to work by typing "/csvs/mycsvfile.csv"
Because now i just can type "https:localhost:8080/csv/get/player/mycsvfile.csv"
Is it possible?