zoukankan      html  css  js  c++  java
  • SpringMVC(二)传值

    1、HelloController.java

    通过model.addAttribute(key,value)进行传值

    package zttc.itat.controller;  
    import org.springframework.stereotype.Controller;  
    import org.springframework.web.bind.annotation.RequestMapping;  
      
    @Controller  
    public class HelloController{  
        //RequestMapping表示用哪个URL来对应  
        @RequestMapping{{"/hello","/"}}  
        public String hello(String username, Model model){  
               System.out.println("hello");  
    model.addAttribute(
    "username", username);
           model.addAttribute(username);//默认使用对象的类型作为key,即
    model.addAttribute("string",username)
           System.out.println(username);
               return "hello";  
         }   
        @RequestMapping{{"/welcome"}}  
         public String welcome(){  
               System.out.println("welcome");  
               return "welcome";  
          }   
    }  

    2、hello.jsp

    <head>  
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
    <title></title>  
    </head>  
    <body>  
    <h1>hello!! ${username}</h1>  
    <h2>hello!!!! ${string}</h2>  
    </body>

    在客户端地址栏输入:localhost……/hello?username=value

  • 相关阅读:
    flask的类视图
    flask的消息提示flash和abort
    css—left和margin-left的区别
    Git(2)—特性
    JS 基础
    css
    搭建vue环境
    Git(1)—基础
    C中 输出格式
    软件测试_对于堆栈的单元测试
  • 原文地址:https://www.cnblogs.com/Donnnnnn/p/5746744.html
Copyright © 2011-2022 走看看