@RequestMapping("hello"),访问的时候需要输入/hello
需要注意@RequestMapping("show5/{id}/{name}")
在网址栏输入:localhost:8080/hello/show5/666/deyi
代表id=666,name=deyi;
在RequestMapping里面,注意id要带大括号{}。
package com.day01springmvc.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
/**
* @ Author :ShaoWei Sun.
* @ Date :Created in 20:58 2018/11/16
*/
@Controller
@RequestMapping("hello")
public class HelloController2 {
/**
*3、占位符映射
* 语法:@RequestMapping(value=”user/{userId}/{userName}”)
* 请求路径:http://localhost:8080/hello/show5/1/james
* @param ids
* @param names
* @return
*/
@RequestMapping("show5/{id}/{name}")
public ModelAndView test5(@PathVariable("id") Long ids ,@PathVariable("name") String names){
ModelAndView mv = new ModelAndView();
mv.addObject("msg","占位符映射:id:"+ids+";name:"+names);
mv.setViewName("hello2");
return mv;
}
}