@PathVariable和RequestParam差不多

package com.exa.de.controller;

import org.springframework.boot.jdbc.metadata.HikariDataSourcePoolMetadata;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class ParamsController {
public static final String PAGE="param";
/*ModelAndView=Model+View>>>Model=模型;View=视图;
设置转向地址
将底层获取的数据进行存储(或者封装)
最后将数据传递给View
Model是每一次请求可以自动创建,但是ModelAndView 是需要我们自己去new的-
*/

@RequestMapping("/path/{id}/{type}")
public ModelAndView path(@PathVariable(required = false)int id, //http://localhost:8080/path/07/霖
@PathVariable(required = false)String type){

//required = false传值给后台

System.out.println("id="+id);
System.out.println("type+"+type);
ModelAndView view =new ModelAndView(PAGE);
view.addObject("id",id);
view.addObject("type",type);
return view;
}
}

 

posted on 2022-04-26 11:29  阿霖找BUG  阅读(57)  评论(0)    收藏  举报