问题
Would it be possible to accept csv types? service.path(appPath).accept(mediaType).get(String.class)
There's no MediaType.TEXT_CSV defined in javax.ws.rs.core.MediaType. Have I missed something?
I am currently on Jersey 1.1.6.
Many thanks.
回答1:
You could define your own media type:
public final static String TEXT_CSV = "text/csv";
public final static MediaType TEXT_CSV_TYPE = new MediaType("text", "csv");
回答2:
csv is nothing but comma seperated text file
you can always use text\plain
as media type to deal with CSV files - and deal with the CSV using frameworks such as Open CSV.
Or (in case of fileupload)
@Consumes(MediaType.MULTIPART_FORM_DATA)
public String process(@FormDataParam("file") InputStream csv) throws IOException {
//Process CSV file
}
来源:https://stackoverflow.com/questions/14520950/mediatype-text-csv-for-jersey