1,web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name></display-name>
<!--配置前端控制器 -->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!--设置配置文件的位置 -->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!--前段控制器设置url -->
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping> <welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

2,springmvc_servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<!--配置handler -->
<context:component-scan base-package="com.songyan.controller"></context:component-scan>
<!--映射器 -->
<!--适配器2 -->
<mvc:annotation-driven></mvc:annotation-driven>
<!--解析器 -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView"></property>
<property name="prefix" value="/WEB-INF/jsp/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
</beans>

3,controller

@Controller声明该类为Controller
@RequestMapping("user")加在类前面:url细化,(url的一部分)
@RequestMapping("user")加在方法前面:制定访问的url路径(url一部分)

package com.songyan.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView; @Controller
@RequestMapping("user")
public class MyController {
@RequestMapping("hello")
public ModelAndView hello()
{
ModelAndView mav=new ModelAndView();
mav.addObject("message","hahah");
mav.setViewName("index");
return mav; } }

@RequestMapping注解的使用,Controller方法返回值的更多相关文章

  1. SpringMVC的@RequestMapping和Controller方法返回值

    本节内容: @RequestMapping Controller方法返回值 一.@RequestMapping 通过@RequestMapping注解可以定义不同的处理器映射规则. 1. URL路径映 ...

  2. SpringMVC入门(二)—— 参数的传递、Controller方法返回值、json数据交互、异常处理、图片上传、拦截器

    一.参数的传递 1.简单的参数传递 /* @RequestParam用法:入参名字与方法名参数名不一致时使用{ * value:传入的参数名,required:是否必填,defaultValue:默认 ...

  3. SprimgMVC学习笔记(五)—— Controller方法返回值

    一.返回ModelAndView controller方法中定义ModelAndView对象并返回,对象中可添加model数据.指定view. /** * 查询商品列表 * @return */ @R ...

  4. Controller方法返回值

    1. 返回ModelAndView controller方法中定义ModelAndView对象并返回,对象中可添加model数据.指定view. //入门程序 第一 包类 + 类包 + 方法名 @Re ...

  5. @RequestMapping与controller方法返回值介绍

    @RequestMapping url映射:定义controller方法对应的url,进行处理器映射使用.@RequestMapping(value="/item")或@Reque ...

  6. 《SpringMVC从入门到放肆》十一、SpringMVC注解式开发处理器方法返回值

    上两篇我们对处理器方法的参数进行了分别讲解,今天来学习处理器方法的返回值. 一.返回ModelAndView 若处理器方法处理完后,需要跳转到其它资源,且又要在跳转资源之间传递数据,此时处理器方法返回 ...

  7. SpringMVC中 controller方法返回值

    1)ModelAndView @RequestMapping(value="/itemEdit") public ModelAndView itemEdit(){ //创建模型视图 ...

  8. Spring MVC中 controller方法返回值

    1.返回ModelAndView 定义ModelAndView对象并返回,对象中可添加model数据.指定view 2.返回String 1.表示返回逻辑视图名 model对象通过 model.add ...

  9. springmvc controller方法返回值

随机推荐

  1. Codis+redis 集群测试

    Codis 是一个分布式 Redis 解决方案, 对于上层的应用来说, 连接到 Codis Proxy 和连接原生的 Redis Server 没有显著区别 (不支持的命令列表), 上层应用可以像使用 ...

  2. 串的模式匹配算法(求子串位置的定位函数Index(S,T,pos))

    串的模式匹配的一般方法如算法4.5(在bo4-1.cpp 中)所示:由主串S 的第pos 个字 符起,检验是否存在子串T.首先令i 等于 pos(i 为S 中当前待比较字符的位序),j 等于 1(j ...

  3. [06] 盒模型 + auto 居中 + 垂直合并

    1.盒模型 盒子模型有两种,分别是 ie 盒子模型和标准 w3c 盒子模型. 标准(W3C)模型中:CSS中的宽(width) = 内容 (content)的宽 CSS中的宽(width) = 内容( ...

  4. 解决在极光推送的时候会出现一个 JPush提示:缺少统计代码

    <span style="font-size:14px;"> @Override protected void onResume(){ super.onResume() ...

  5. [Evernote]印象笔记使用经验技巧

    一    软件使用      现在使用Windows客户端的印象笔记 + iPhone移动端印象笔记 + chrome浏览器剪藏插件.      在试用了很多云笔记后,还是选择了印象笔记,并且有许多的 ...

  6. LOJ 6057 - [HNOI2016]序列 加强版再加强版

    Description 给定一个长度为 \(n\le 3*10^6\) 的序列 \(q\le 10^7\) 次询问每次求区间 \([l,r]\) 的所有子区间的最小值的和 询问随机 Solution ...

  7. HDFS 的Trash回收站

    1)在core-site.xml文件中添加这个配置 在每个节点(不仅仅是主节点)上添加配置 core-site.xml,增加如下内容 <property> <name>fs.t ...

  8. 校内训练0609 problem c

    [题目大意] 给一棵树,求有多少条路径满足总和-最大值 是P的倍数 n<=10^5, P<=10^7 [题解] 一看就是点分治嘛 不考虑子树合并,考虑poj1741的做法,每次考虑经过重心 ...

  9. bzoj4756 [Usaco2017 Jan]Promotion Counting

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=4756 [题解] dsu on tree,树状数组直接上 O(nlog^2n) # inclu ...

  10. 2017年上海金马五校程序设计竞赛:Problem E : Find Palindrome (字符串处理)

    Description Given a string S, which consists of lowercase characters, you need to find the longest p ...