亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

嘗試使用 java spring boot、hibernate 和 thmyeleaf

嘗試使用 java spring boot、hibernate 和 thmyeleaf

幕布斯6054654 2021-07-02 14:00:19
我已經構建了我的控制器、客戶端和地址類(模型)以及用于索引和添加的模板。當我嘗試測試驗證時,spring 返回:出現意外錯誤(類型=內部服務器錯誤,狀態=500)。在組 [javax.validation.groups.Default, ] 約束違規列表期間,類 [com.pooltracker.models.Address] 的驗證失?。篬 ConstraintViolationImpl{interpolatedMessage='Invalid', propertyPath=zipCode, rootBeanClass=class com .pooltracker.models.Address, messageTemplate='Invalid'} ConstraintViolationImpl{interpolatedMessage='may not be null', propertyPath=state, rootBeanClass=class com.pooltracker.models.Address, messageTemplate='{javax.validation.constraints.NotNull .message}'} ConstraintViolationImpl{interpolatedMessage='不能為空', propertyPath=street, rootBeanClass=class com.pooltracker.models.Address, messageTemplate='不能為空'我了解到 hibernate 無法處理驗證地址類。我偶然發現了 bean 驗證的主題。我對此很陌生,并試圖找到解決我的問題的最佳方法,而不會在目前的兔子洞中走得太遠。下面是我的控制器和模型。@Controller@RequestMapping("clients")public class ClientController {    @Autowired    private ClientDao clientDao;    @Autowired    private AddressDao addressDao;    @RequestMapping(value = "")    public String index(Model model) {                model.addAttribute("clients", clientDao.findAll());        model.addAttribute("title", "My Clients");                return "clients/index";    }    @RequestMapping(value = "add", method = RequestMethod.GET)    public String displayAddClientForm(Model model) {                model.addAttribute("title", "Add Client");        model.addAttribute(new Client());        return "clients/add";    }    @RequestMapping(value = "add", method = RequestMethod.POST)    public String processAddClientForm(@ModelAttribute @Valid Client newClient,                                       Errors errors, Model model) {         if (errors.hasErrors()) {            model.addAttribute("title", "Add Client");            model.addAttribute("client", newClient);            return "clients/add";        }                clientDao.save(newClient);        return "redirect:";    }}
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 226 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號