package com.exa.de.controller; import org.springframework.boot.jdbc.metadata.HikariDataSourcePoolMetadata; import org.springframework.stereotype.Controller; 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("/param") public ModelAndView param(@RequestParam(value = "id",defaultValue = "0")int id,//value名字;defaultValue初始值,这两个一定要//http://localhost:8080/param?id=100,输出100 @RequestParam(value = "type",required = false,defaultValue = "")String type){//http://localhost:8080/param?id=lin,输出0 lin //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; } }
param.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>测试页面</title>
</head>
<body>
<h2>${id}</h2>
<body>
<h2>${type}</h2>
</body>
</html>
本文来自博客园,作者:阿霖找BUG,转载请注明原文链接:https://www.cnblogs.com/lin-07/articles/16193104.html
浙公网安备 33010602011771号