2013年9月10日星期二

springMVC form submission has asked

Previously been used ssh2, but today encountered an ssh program , using struts1, I will not use , do not want to use . But did not dare to import strus2 package , use the springMVC, to form requests can not know how to get it , like my code is as follows :

///**strus2很容易就把 表单里的请求封装在user对象中*/
UserAction {
private User user;

public void setUser(User user) {this.user=user;}
public User getUser(){return user;}
private IUserService userService;

public String save() {
userService.save(user);
}


then use the spring to achieve similar functionality it ? I do not want to request a parameter set to the object.
------ Solution ---------------------------------------- ----
on spring MVC too many examples . Do not explain , you see examples easier.
http://www.mkyong.com/spring-mvc/spring-mvc-hello-world-example/
------ Solution ------------ --------------------------------
spring mvn is based on the injection , upstairs in fact model is equivalent to HttpServletRequest HttpServletResponse
------ For reference only --------------------------------- ------
Thank slightly, so quickly approach slightly
------ For reference only -------------------- -------------------
spring mvc example , a two , can not tell the landlord to see relevant information on the OK
- ---- For reference only ---------------------------------------
public ; String save () (@ ModelAttribute User user)
{...}
The name input form set user attributes.
That's it .
------ For reference only -------------------------------------- -
spring mvc struts2 more convenient than

As long as the form in the control and domain name value or DTO able to help you on the corresponding injected into it.

what you want in the Senate when brought nothing , spring will automatically help you complete injection .


@RequestMapping(value="请求的路径",method = RequestMethod.POST) //只能post传递
public String save(Model model ,User u){
 // TODO 调用业务方法
 model.addAttribute("key","value");//返回数据给页面   可以使用el表达式 ${key}获取
 return "url";
}

------ For reference only ----------------------------------- ----
received , the problem has been resolved slightly.
------ For reference only -------------------------------------- -
how to solve ?

没有评论:

发表评论