springmvc的使用
标题
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
/*
* 这是控制层
*/
@Controller
public class MyController {
@RequestMapping(value="/hello",method=RequestMethod.GET)
public ModelAndView hello(@RequestParam(name="id",required=false)Integer id){ //可以简化成 (int id)
System.out.println(id);
System.out.println("hello GET Spring");
return new ModelAndView("/comm/hello");
}
@RequestMapping(value="/hello",method=RequestMethod.POST)
public ModelAndView hello2(@RequestParam(name="title")String title){
System.out.println(title);
System.out.println("hello POST Spring");
return new ModelAndView("/comm/hello");
}
}

![springmvc的使用
[编程语言教程]](https://www.zixueka.com/wp-content/uploads/2024/01/1706709619-0a907522950055f.jpg)
