我想在addItem的页面输入了信息之后点提交,可以提交表单然后跳转到queryItems的页面。请问要怎么写?是在Controller里写还是在JSP页面里写?
基础问题,刚开始学,求回答,非常感谢。
两个Jsp页面:
addItem.jsp
添加输入姓名
输入邮箱
queryItems.jsp
pageEncoding="UTF-8"%>
查询用户列表
----
我的Controller类
@Controller
@RequestMapping("/items")
public class ItemsController {
@Autowired
private ItemsService itemsService;
@RequestMapping("/query")
public ModelAndView queryItems() throws Exception{
List itemsList = itemsService.findAllUser();
ModelAndView mv = new ModelAndView();
mv.addObject("userList", itemsList);
mv.setViewName("queryItems");
return mv;
}
@RequestMapping("/add")
public ModelAndView addItem(String username, String useremail) throws Exception{
User user = new User();
user.setUser_name(username);
user.setUser_email(useremail);
itemsService.insertUser(user);
ModelAndView mv = new ModelAndView();
mv.addObject(user);
mv.setViewName("addItem");
return mv;
}
}