をオーバーライドするビューを返すコントローラーがありますAbstractPdfView
。ユーザーがブラウザーから PDF フォームを保存しようとすると、要求パスを保存しようとするという事実を除いて、うまく機能します (妥当なようですが、私が望むものではありません)。
コントローラーのコードは次のとおりです。
public class MealPlanPDFController {
private MealPlannerDao mealPlannerDao;
private UserDao userDao;
//protected SessionFactory sessionFactory;
@Autowired
public void setMealPlanDao(MealPlannerDao mealPlannerDao) {
this.mealPlannerDao = mealPlannerDao;
}
@Autowired
public void setUserDao(UserDao userDao) {
this.userDao = userDao;
}
@RequestMapping(value = "{id}", method = RequestMethod.GET)
@Transactional
protected ModelAndView handleRequest(@PathVariable Long id, HttpServletRequest request) throws Exception {
System.out.println(request.getContextPath());
ModelAndView modelView = new ModelAndView(new MealPlanPDFView());
MealPlan mealPlan = mealPlannerDao.getMealPlan(id, true);
ServletContext servletContext = request.getSession().getServletContext();
Resource res = new ServletContextResource(servletContext,"/images/logo.png");
URL url = res.getURL();
modelView.addObject("mealPlan",mealPlan);
modelView.addObject("imageURL",url);
System.out.println(url.getPath());
return modelView;
}
}
したがって、リクエストパスは次のとおりです。
api/mealplanpdf/1
ここで、1 は MealPlan の ID です。
応答について、私はそれが好きmealplan_1.pdf
です。
理にかなっていますか?どうすればそれを行うことができますか?
ありがとう