1. HOME 控制器

    package ghy.webapp.myapp;
    
    import java.text.DateFormat;
    import java.util.Date;
    import java.util.Locale; import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.web.bind.annotation.RequestParam; /**
    * Handles requests for the application home page.
    */
    @Controller
    public class HomeController { private static final Logger logger = LoggerFactory.getLogger(HomeController.class); /**
    * Simply selects the home view to render by returning its name.
    */
    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String home(Locale locale, Model model) {
    logger.info("Welcome home! The client locale is {}.", locale); Date date = new Date();
    DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale); String formattedDate = dateFormat.format(date); model.addAttribute("serverTime", formattedDate ); return "home";
    } @RequestMapping(value = "/Two", method = RequestMethod.GET)
    public String Two(
    int id,Model model
    ) {
    logger.info("two"); System.out.println("hello2 action:"+id);
    model.addAttribute("name", "huangjie");
    //这个只有值没有键的情况下,使用Object的类型作为key,String-->string
    model.addAttribute("ok"); return "Two";
    } }
  2. Two.jsp 视图
    <%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>欢迎</title>
    </head>
    <body>
    <h2>Hello World!</h2> <form action="login">
    用户名:<input id="username" name="username" type="text" value='${name}'></input><br>
    密 码:<input id="username" name="password" type="password"></input><br>
    <input type="submit">
    </form>
    <span>当前IP:<%=request.getRemoteAddr() %></span>
    </body>
    </html>
  3. Two控制器
    package ghy.webapp.myapp;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestParam;
    import org.springframework.web.bind.annotation.ResponseBody; @Controller
    public class TwoController { @RequestMapping("login") //用来处理前台的login请求
    private @ResponseBody String hello(
    @RequestParam(value = "username", required = false)String username,
    @RequestParam(value = "password", required = false)String password
    ){
    return "Hello "+username+",Your password is: "+password; } }

    环境:sts +tomcat

  4. 运行 http://localhost:8080/myapp 执行home控制器 ,http://localhost:8080/myapp/Two?id=3525是调用 Two控制器传参id

5.下载地址:。下载

最新文章

  1. 初探React,将我们的View标签化
  2. AndroidStudio导入Library
  3. Unity3D脚本18:可视化辅助设置类 Gizmos
  4. HDU 4610 Cards (合数分解,枚举)
  5. C# DllImport的用法
  6. C++面试题:++i和i++哪个效率高?
  7. WebApi2官网学习记录---Tracing
  8. A Byte of Python 笔记(12)python 标准库:sys、os,更多内容
  9. Delphi + Asm - TBits类的学习
  10. 手动添加PopMenu出现的问题
  11. hdu2413(二分+二分匹配)
  12. 原生JS—实现图片循环切换的两种方法
  13. ecshop PC版本智能跳转到对应手机版页面
  14. 【手记】走近科学之为什么明明实现了IEnumerable&lt;T&gt;的类型却不能调用LINQ扩展方法
  15. 方法的覆盖(override)
  16. Node 各个版本支持ES2015特性的网站
  17. ES6 新加的类型Symbol()
  18. (白话理解)CAS机制
  19. iframe获取父、子窗口的元素和方法
  20. Styles in Windows Phone

热门文章

  1. iOS viewDidLoad 什么时候调用
  2. RequireJS 2.0初探
  3. scope的范围
  4. sql server博客
  5. Word调整表格大小
  6. EF4.4 升级EF6.0问题总结
  7. 《linux 内核全然剖析》 chapter 4 80x86 保护模式极其编程
  8. javascript快速入门12--函数式与面向对象
  9. 关于JS里的函数作用域链的总结
  10. numpy基础知识