org.springframework.expression.spel.SpelEvaluationException: EL1007E: Property or field 'chargesName' cannot be found on null

后端 未结 2 683
余生分开走
余生分开走 2020-12-21 16:39

My project based on spring boot,Thymeleaf,mysql,html and Jquery.

My scenario is to Get the List iterate and show the d

相关标签:
2条回答
  • 2020-12-21 17:18

    You used the form at the top of your html page:

    <form method="post" th:object="${entSetCharges}" th:action="@{/updatesetcharges}">
    

    The th:field="*{chargesName} is bound to the object/bean inside your th:object="${entSetCharges}. Meaning that you are searching for a chargesName field inside your entSetCharges object which does not exist or is null.

    Solution:

    • Maybe change your th:field="*{chargesName}" to ${savedcharges.chargesName} expression to access your object's field.

    • Try adding respondResult.addObject("entSetCharges",new EntSetCharges()); above your return line. Your view doesn't automatically create this object for you.

    0 讨论(0)
  • 2020-12-21 17:36

    I init the entity object like respondResult.addObject("entSetCharges",new EntSetCharges());

    @GetMapping(value="/setchargeslist")
        public ModelAndView doGetSetchargesList()
        {
            List<EntSetCharges> listCharges = new ArrayList<>();
            ModelAndView respondResult = new ModelAndView("SetCharges");
            try {
                /*Get the set charges list*/
                listCharges = serSetCharges.doGetSetChargesList();
                if(listCharges!=null)
                {
                respondResult.addObject("savedchargeslist",listCharges);
                respondResult.addObject("entSetCharges",new EntSetCharges());
                }
                else
                {
                    respondResult.addObject("savedchargeslist",new ArrayList<>());
                }
    
            } catch (Exception e) {
                // TODO: handle exception
            }
            return respondResult;
        }
    
    0 讨论(0)
提交回复
热议问题