博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
spring mvc:内部资源视图解析器(注解实现)@Controller/@RequestMapping
阅读量:7206 次
发布时间:2019-06-29

本文共 2462 字,大约阅读时间需要 8 分钟。

spring mvc:内部资源视图解析器(注解实现)@Controller/@RequestMapping

项目访问地址:

http://localhost:8080/guga2/hello/print

http://localhost:8080/guga2/hello

 

用到的注解类:

org.springframework.stereotype.Controller;org.springframework.web.bind.annotation.RequestMapping;org.springframework.web.bind.annotation.RequestMethod;

  

视图模型类

org.springframework.ui.ModelMap;

 

 

本例中,包名:springweb 

本例中有三个xml配置文件:web.xml, applicationContext.xml,xxxx-servlet.xml

web.xml

contextConfigLocation
/WEB-INF/applicationContext.xml
encodingFilter
org.springframework.web.filter.CharacterEncodingFilter
encoding
UTF-8
encodingFilter
/*
org.springframework.web.context.ContextLoaderListener
springweb
org.springframework.web.servlet.DispatcherServlet
1
springweb
/

  

applicationContext.xml

  

springweb-servlet.xml

  

jsp代码

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%><%@ page isELIgnored="false" %>
hello world${message}

  

HelloController.java代码

1.项目/hello访问代码

import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.ui.ModelMap;@Controller@RequestMapping(value="/hello")public class HelloController {		@RequestMapping( method=RequestMethod.GET)	public String printHello(ModelMap model)	{		model.addAttribute("message", "spring mvc framework映射网页与请求实例");		return "hello";			}	}

  

2.项目/hello/print访问代码

import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.ui.ModelMap;@Controllerpublic class HelloController {		@RequestMapping(value="/hello/print", method=RequestMethod.GET)	public String printHello(ModelMap model)	{		model.addAttribute("message", "spring mvc framework映射网页与请求实例");		return "hello";			}	}

  

 

转载地址:http://uwlum.baihongyu.com/

你可能感兴趣的文章
mysql--SQL编程(关于mysql中的日期) 学习笔记2
查看>>
jquery 请求jsp传递json数据的方法
查看>>
Repeater绑定事件ItemDataBound中获取数据库中数据
查看>>
草长莺飞,总归一字
查看>>
HDOJ 2097
查看>>
计算机学科漫谈
查看>>
mac下配置openfire
查看>>
自定义控件实现(转)
查看>>
如何确认访客所在的国家
查看>>
跟着8张思维导图学习javascript
查看>>
InnoSQL/MySQL并行复制的实现与配置
查看>>
JDBC连接MySQL数据库及演示样例
查看>>
第38周五
查看>>
windows下Emacs的安装与配置
查看>>
WF4 常用类<第二篇>
查看>>
mongo文件空间
查看>>
NSArray中存的是实体时的排序
查看>>
搜索框中“请输入搜索keyword”
查看>>
CentOS6.5与XP双系统安装
查看>>
Python 更新set
查看>>