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>

 

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