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.下载地址:。下载

srping mvc学习的更多相关文章

  1. MVC学习系列4--@helper辅助方法和用户自定义HTML方法

    在HTML Helper,帮助类的帮助下,我们可以动态的创建HTML控件.HTML帮助类是在视图中,用来呈现HTML内容的.HTML帮助类是一个方法,它返回的是string类型的值. HTML帮助类, ...

  2. Spring MVC 学习 -- 创建过程

    Spring MVC 学习 -- 创建过程 Spring MVC我们使用的时候会在web.xml中配置 <servlet> <servlet-name>SpringMVC< ...

  3. 前端MVC学习总结——AngularJS验证、过滤器

    前端MVC学习总结--AngularJS验证.过滤器 目录 一.验证 二.过滤器 2.1.内置过滤器 2.1.1.在模板中使用过滤器 2.1.2.在脚本中调用过滤函数 2.2.自定义过滤器 三.指令( ...

  4. 《Spring MVC学习指南》怎么样?答:书名具有很大的欺骗性

    2016年6月21日 最近,因为工作需要,我从网上买了一本<Spring MVC学习指南>,ISBN编号: 978-7-115-38639-7,定价:49.00元.此书是[美]Paul D ...

  5. PHP实例开发(3)PHP中MVC学习之ThinkPHP

    PHP中MVC学习之ThinkPHP 1.什么是MVC MVC本来是存在于Desktop程序中的,M是指数据模型,V是指用户界面,C则是控制器.使用MVC的目的是将M和V的实现代码分离 MVC是一个设 ...

  6. Asp.net MVC 学习系列(一)序

    题外话 公司本月开始提供早餐服务,2块天一餐,包括粥,两个包(听说是利口福供应的),一个鸡蛋.良心企业.公司原本有一个内部订餐系统,用Delphi开发的,开发的人早就走光了,也没有留下什么文档,现在项 ...

  7. MVC学习(四)几种分页的实现(3)

    在这篇MVC学习(四)几种分页的实现(2)博文中,根据URL中传入的两个参数(页码数,首页.上一页.下一页.末页的标记符)来获得对应的分页数据, 只是传入的参数太多,调用起来不太方便(标记符不能够写错 ...

  8. ASP.NET MVC学习之Ajax(完结)

    一.前言 通过上面的一番学习,大家一定收获不少.但是总归会有一个结束的时候,但是这个结束也意味着新的开始. 如果你是从事ASP.NET开发,并且也使用了第三方控件,那么一定会觉得ASP.NET开发aj ...

  9. ASP.NET MVC学习之视图篇(2)

    继ASP.NET MVC学习之视图(1)学习 4.HTML辅助器 虽然在ASP.NET MVC中我们已经摆脱了ASP.NET的控件,但是对于页面中需要循环标签的情况依然还是存在,可能很多人认为用for ...

随机推荐

  1. 1.5(java学习笔记)this关键字

    this关键字主要有三个作用 1.调用本类中的属性. public class TextThis { public static void main(String[] args){ Person p1 ...

  2. C语言计算器

    地址:  https://wenda.so.com/q/1371173683061754?src=140

  3. 解决Ubuntu 14下,PhpStorm 9.x 编辑器界面中文乱码的问题

    在Ubuntu 14中,安装了 PhpStorm 9.02,发现 软件界面中文乱码,但是源码编辑处却显示正常,如下图所示: 很奇怪,猜想,应该是软件界面字体有问题,选了一个没有包含中文字体的字体.先前 ...

  4. 【java】java中直接根据Date 获取明天的时间

    展示代码: @Test public void dateTest(){ Date now = new Date(); System.out.println(now); // java.util.Dat ...

  5. Discuz! 6.x/7.x 版本 前台任意代码执行漏洞

    一.漏洞原理: 由于php5.3.x版本里php.ini的设置里request_order默认值为GP,导致Discuz! 6.x/7.x 全局变量防御绕过漏洞. include/global.fun ...

  6. NTFS数据流和web安全

    NTFS流简单介绍: NTFS因为它的稳定性 强大的功能 以及它所提供的安全性而成为一种更优越的文件系统,NTFS交换数据流(ADSs)是为了和Macintosh的HFS文件系统兼容而设计的,它使用资 ...

  7. Actionscript 3 自定义 matedata

    metadata就是元数据 反应一个类本质的属性 可以通过describeType(obj)来得到反应该对象的xml 要自定义元数据,如[MyMatedata()] package {  public ...

  8. C# 关键字 Visual Studio 2012

    C# 关键字 Visual Studio 2012 其他版本 关键字是对编译器具有特殊意义的预定义保留标识符. 它们不能在程序中用作标识符,除非它们有一个 @ 前缀. 例如,@if 是有效的标识符,但 ...

  9. POJ Cow Exhibition

    题目链接:Click Here~ 题目意思自己看吧. 算法分析: 对我来想是没有想到,最后看别人的博客才知道的.要把当中的一个条件当作体积.由于两个条件都存在负数,所以还要先保证最后不会再体积中出现负 ...

  10. Ubuntu(Debian)的aptitude与apt-get的区别和联系

    Ubuntu(Debian)的aptitude与apt-get的区别和联系 aptitude 与 apt-get 一样,是 Debian 及其衍生系统中功能极其强大的包管理工具.与 apt-get 不 ...