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");
    }
    
}
hmoban主题是根据ripro二开的主题,极致后台体验,无插件,集成会员系统
自学咖网 » springmvc的使用