【发布时间】:2017-03-04 07:53:37
【问题描述】:
我需要你的帮助。没有你的帮助,我的大脑会爆炸!我正在 Spring MVC + JSP 上编写测验应用程序。
我现在做了什么:
1.我创建了HashMap +硬编码正确答案。
2.我创建了@RequestMapping(value = "/level_one", method = RequestMethod.POST)
public String levelOne() {
return "levelone";
}
应该如何: pics
然后我就僵住了,我不知道该做什么以及如何将@RequestMaping 中的这段代码与HashMap 结合起来,并在jsp 中编写代码以使其可见和可点击??? 在控制器中我写道:
package ua.kiev.prog;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import java.util.HashMap;
import java.util.Map;
@Controller
@RequestMapping("/")
public class MyController {
final private String rightAnswerOne = "Dance";
@ModelAttribute("answerList")
public Map answerList() {
Map<String, String> answerList = new HashMap<String, String>();
answerList.put("one", "Sandbox");
answerList.put("two", "Pixel");
answerList.put("three", "Game");
answerList.put("four", "Picture");
return answerList;
}
@RequestMapping(value = "/level_one", method = RequestMethod.POST)
public String levelOne() {
return "levelone";
}
}
【问题讨论】:
标签: java spring jsp spring-mvc model-view-controller