我想知道是否可以使用JSP页面中的标记调用控制器方法,有点像在JSF中完成的。使用SpEL和eval调用控制器方法
我的控制器
@Controller(value="planesController")
@RequestMapping({"/planes"})
public class PlanesController {
@Autowired
private PlanesDAO planesDAO;
public List<Plane> allPlanes(){
return planesDAO.getAll();
}
我的JSP
<sf:form>
<s:eval expression="planesController.allPlanes()" var="planes" />
<sf:checkboxes items="${planes}" path="planes" id="avions"/>
</sf:form>
我不断收到异常:
org.springframework.expression.spel.SpelEvaluationException: EL1007E:(pos 0): Field or property 'planesController' cannot be found on null
我知道我可以使用model.addAttribute,但是我从几个JSP页面调用这个方法,我认为其中的一个标记允许从视图访问bean。
我使用的是春天提前
答案在[forum]上提供(http://forum.springsource.org/showthread.php?104736-Using-SpEL-and-eval-to-call-a-controller-method):使用' s:eval expression =“@ planesController.allPlanes()”var =“planes”/>'。 – 2012-05-03 09:40:24