那么这个时候如果希望通过SpringMVC自动实现参数的赋值操作。只需要在参数上做一个修改。
package com.gwolf.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import com.gwolf.vo.Emp;
@Controller
@RequestMapping("/pages/emp/*")
public class EmpAction {
Logger logger = LoggerFactory.getLogger(this.getClass());
@RequestMapping("add")
public ModelAndView add(Emp emp) {
ModelAndView md = new ModelAndView("/pages/show.jsp");
System.out.println(emp);
return md;
}
@RequestMapping("remove")
public ModelAndView remove(int id) {
ModelAndView md = new ModelAndView("/pages/show.jsp");
logger.info(id * 2 + "--------");
System.out.println(id * 2 + "--------");
return md;
}
@RequestMapping("list")
public ModelAndView list(@RequestParam(value="cp",defaultValue="1") int currentPage,
@RequestParam(value="ls",defaultValue="10") int lineSize,
@RequestParam(value="col",defaultValue="ename") String colum,
@RequestParam(value="kw",defaultValue="") String keyword) {
ModelAndView md = new ModelAndView();
System.out.println("currentPage=" + currentPage);
System.out.println("lineSize=" + lineSize);
System.out.println("colum=" + colum);
System.out.println("keyword=" + keyword);
return md;
}
@RequestMapping("get")
public ModelAndView doGet(int id,HttpServletRequest request,
HttpServletResponse response) {
ModelAndView md = new ModelAndView();
return md;
}
@RequestMapping("echo")
public ModelAndView echo(String msg) {
ModelAndView md = new ModelAndView("/pages/show.jsp");
md.addObject("info","Echo:" + msg);
return md;
}
}