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. ecplise中修改reviewboard密码

    一.概述 如果想在ecplise中修改reviewboard密码,步骤请参考如下图片:

  2. CSS中的text-shadow。

    text-shadow(文字投影),box-shadow(容器投影),border-radius(圆角)这三个属性估计以后用的比较多,记录 一下.目前不支持IE系列(不过可以使用其他方法实现,下文有详 ...

  3. 记录一次Nginx跳转报错的问题

    错误信息如下: An error occurred. Sorry, the page you are looking for is currently unavailable. Please try ...

  4. bzoj3223 文艺平衡树 codevs3303 翻转区间

    splay模版题吧 只有区间翻转 至于为什么要把须翻转区间旋到根 因为查找一个区间可以先找出他左端点左边第一个点和右端点x右边第一个点y 然后将x旋到根节点 y旋到x的右儿子 这样x的右边的点就是所有 ...

  5. NYOJ 127 星际之门(一) (数学)

    题目链接 描述 公元3000年,子虚帝国统领着N个星系,原先它们是靠近光束飞船来进行旅行的,近来,X博士发明了星际之门,它利用虫洞技术,一条虫洞可以连通任意的两个星系,使人们不必再待待便可立刻到达目的 ...

  6. bzoj 1089 SCOI2003严格n元树 递推

    挺好想的,就是一直没调过,我也不知道哪儿的错,对拍也拍了,因为数据范围小,都快手动对拍了也不知道 哪儿错了.... 我们定义w[i]代表深度<=i的严格n元树的个数 那么最后w[d]-w[d-1 ...

  7. bzoj 1191 匈牙利算法

    只需要做一遍匈牙利,只要有一个没法匹配上就break就行了 /************************************************************** Proble ...

  8. MongoDB安装成为Windows服务

    使用以下命令将MongoDB安装成为Windows服务.笔者的MongoDB目录为C:\Program Files\MongoDB\Server\3.6\bin 切换到C:\Program Files ...

  9. MS笔试中的一个关于函数返回的“小”题

    Which of following C++ code is correct ? A. int f() { ); return *a; } B. int *f() { int a[3] = {1,2, ...

  10. 算法题之Leetcode分糖果

    题目: There are N children standing in a line. Each child is assigned a rating value. You are giving c ...