@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;
}
}
本文来自博客园,作者:阿霖找BUG,转载请注明原文链接:https://www.cnblogs.com/lin-07/articles/16194080.html
浙公网安备 33010602011771号