筆者在開發Java發送郵件中遇到一個非常奇怪的事情,在採用了Thymeleaf作爲郵件模板時,報錯如下:
Error resolving template [cert/sendThymeleafMailApi], template might not exist or might not be accessible by any of the configured Template Resolvers
在經歷了一番搜索發現,原來是這裏缺少了註解@ResponseBody,代碼如下:
@GetMapping("/sendThymeleafMailApi")
@ResponseBody
@ApiOperation(value = "App - 發送App信息")
private void sendThymeleafMailApi(@RequestParam(value = "id") Integer id) throws MessagingException {
APPIDINFO appidinfo = certService.appIDInfoById(id);
sendThymeleafMail(appidinfo);
}
注意@Controller
@Controller
@RequestMapping("cert")
@Api
如果是@RestController,則就不需要前面說的註解@ResponseBody了;