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
SpringMVC(二)传值的更多相关文章
- springMVC中传值的时候的乱码问题
springMVC在传值的时候有时候回出现中文乱码的情况.有一种可能就是service的设置的问题. 打开工程中的tomcat中的servers 打开上述文件,找到下面并加上红色字体 <Conn ...
- SpringMVC作用域传值几种方式
一.SpringMVC 作用域传值的几种方式 1 使用原生Servlet 1.1 在 HandlerMethod 参数中添加作用域对象 1.1.1 ServletContext不能在方法参数中获取, ...
- 框架SpringMVC笔记系列 二 传值
主题:SpringMVC(第一节中再回顾复习一次) 学习资料参考网址: 1.http://www.icoolxue.com 2.http://haohaoxuexi.iteye.com/blog/13 ...
- 【springmvc】传值的几种方式&&postman接口测试
最近在用postman测试postman接口,对于springmvc传值这一块,测试了几种常用方式,总结一下.对于postman这个工具的使用也增加了了解.postman测试很棒,有了工具,测试接口, ...
- SpringMVC(二)——流程控制
SpringMVC主要就是用来做流程控制的,这篇博客总结一下如何在流程控制添加Interceptor(拦截器),如何将进行流程Mapping映射解析,如何编写Controller(控制器). 一,首先 ...
- springmvc(二) ssm框架整合的各种配置
ssm:springmvc.spring.mybatis这三个框架的整合,有耐心一步步走. --WH 一.SSM框架整合 1.1.整合思路 从底层整合起,也就是先整合mybatis与spring,然后 ...
- SpringMVC(二) SpringMVC Hello World
准备条件: STS(集成了Spring相关工具的Eclipse) Spring软件包 spring-framework-4.3.3.RELEASE-dist.zip. 步骤: 加入jar包. Ecli ...
- 浅谈SpringMVC(二)
一.SpringMVC的拦截器 1.写类implements HandlerInterceptor public class MyMvcInterceptor implements HandlerIn ...
- SpringMVC(二):RequestMapping修饰类、指定请求方式、请求参数或请求头、支持Ant路径
@RequestMapping用来映射请求:RequestMapping可以修饰方法外,还可以修饰类 1)SpringMVC使用@RequestMapping注解为控制指定可以处理哪些URL请求: 2 ...
- SpringMVC(二六) SpringMVC配置文件中使用mvc:view-controller标签
在springmvc中使用mvc:view-controller标签直接将访问url和视图进行映射,而无需要通过控制器. 参考springmvc.xml内容: <?xml version=&qu ...
随机推荐
- linux如何删除行首的空格
答: sed 's/^ *//' jello.txt > hello.txt
- 实现简单的ORM
介绍 本篇将介绍实现简单的ORM,即:对数据表的通用操作:增.删.改.查 数据访问层 数据访问层类图 类说明: 1.DbProvider(供应):为数据操作提供基本对象,如:连接.操作对象.事务... ...
- linux之cut用法--转载
cut是一个选取命令,就是将一段数据经过分析,取出我们想要的.一般来说,选取信息通常是针对“行”来进行分析的,并不是整篇信息分析的. (1)其语法格式为:cut [-bn] [file] 或 cut ...
- VcCallC#_01
1.C# 代码: using System; using System.Collections.Generic; //using System.Linq; using System.Text; //u ...
- jq 命名空间
$('ul').on("click",function(){console.log('all');});$('ul').on("click.a",functio ...
- RabbitMQ入门_14_Policies
参考资料:https://www.rabbitmq.com/parameters.html#policies A. Policies 的用途 RabbitMQ 有很多可选参数(x-arguments) ...
- Python mysql-表中数据的大量插入
2017-09-06 23:28:26 import pymysql db = pymysql.connect("localhost","root"," ...
- 递推2--过河卒(Noip2002)
递推2--过河卒(Noip2002) 一.心得 写出递推公式就OK了,具体编程还是很简单的 二.题目及分析 过河卒(NOIp2002) [问题描述] 棋盘上A点有一个过河卒,需要走到目标B点.卒行走的 ...
- C++STL3--queue
C++STL3--queue 一.心得 STL的这些东西用法都差不多 二.介绍 queue数据结构中的队列 priority_queue优先队列,插入进去的元素都会从大到小排好序 PS:在priori ...
- 递归C++
递归C++ 一.递归简介 自己调用自己 二.递归写法 2.1 写法介绍 先写出问题的递推公式 递归部分的边界条件就是递推公式中的边界条件 递归部分的主体部分就是递推公式中的主体部分 2.2 实例 (1 ...