我有一个使用案例,即我需要把国防军归还给我们产生的用户。 看来,我需要做的是利用这一情况下的应急能力,但我有两点不很清楚。
- How can I redirect the user -- let s pretend they don t have the permissions to access this page? How can I redirect them to a separate controller?
- Am I able to set the response encoding?
- Can I achieve either of these two without bringing in the HttpResponse as a parameter to my RequestMapping?
页: 1 例:
@Controller
@RequestMapping("/generate/data/pdf.xhtml")
public class PdfController {
@RequestMapping
public ResponseEntity<byte []> generatePdf(@RequestAttribute("key") Key itemKey) {
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentType(MediaType.valueOf("application/pdf"));
if (itemKey == null || !allowedToViewPdf(itemKey)) {
//How can I redirect here?
}
//How can I set the response content type to UTF_8 -- I need this
//for a separate controller
return new ResponseEntity<byte []>(PdfGenerator.generateFromKey(itemKey),
responseHeaders,
HttpStatus.CREATED);
}
我真的希望不要在反应中 pull。 我的管制人员迄今没有这样做,我很仇恨,必须把它完全带进去。