springMvc-reset风格和对静态资源的管理
1.所谓rest风格及比较优雅的,没有一大堆后缀的风格
2.对静态资源的管理,及样式、图片等不需要springMvc过滤
代码:
1.在springMvc的配置文件中添加mvc标签
<?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.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<!-- 使用注解的包,包括子集 -->
<context:component-scan base-package="com.java1234"/>
<mvc:annotation-driven/>
<mvc:resources mapping="/resources/**" location="/images/"/>
<mvc:resources mapping="/resources2/**" location="/css/"/>
<!-- 视图解析器 -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp"></property>
</bean>
</beans>
2.在controller中添加获取路径参数的注解
package com.java1234.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import com.java1234.model.Article;
@Controller
@RequestMapping("/article")
public class ArticleController {
@RequestMapping("/list")
public String list(Model model){
return "article/list";
}
@RequestMapping("/details/{id}")
public ModelAndView details(@PathVariable("id") int id){
ModelAndView mav=new ModelAndView();
if(id==1){
mav.addObject("article", new Article("文章一","文章一的内容"));
}else if(id==2){
mav.addObject("article", new Article("文章二","文章二的内容"));
}
mav.setViewName("article/details");
return mav;
}
}
最新文章
- mac下搭建redis环境
- WCF 定义SOAP和REST风格的webservice
- innodb_strict_mode
- c语言趣味
- LINQ 学习笔记(1)
- swift 实现漂亮的粒子效果CAEmitterLayer
- poj2262---素数(质数)的判断
- Velocity缓存与穿透(转)
- PAT (Advanced Level) 1070. Mooncake (25)
- app与后台交互之间的几种安全认证机制
- 【iOS】swift 枚举
- Java笔记(day9~day10)
- JMeter学习笔记02-基础介绍
- TestLink环境搭建及用例导入
- Luogu P3346 [ZJOI2015]诸神眷顾的幻想乡 广义SAM 后缀自动机
- 商务通服务器版LR_Data目录下相关配置文件
- python 生成器、列表解析式、yield、迭代器
- 009 使用servlet API作为参数
- topcoder srm 662 div1
- (转)Floyd算法
热门文章
- SQL查询 若为空显示默认值
- FormsAuthentication.RedirectFromLoginPage 登录
- SuperSocket使用自定义协议与服务端通信发送实例
- [java基础]short s1 = 1; s1 = s1 + 1;有什么错?short s1 = 1; s1 += 1;有什么错?
- 第三章 Goroutine调度策略(16)
- cinder服务状态up/down的源码梳理
- CodeForces 118C 【模拟】
- jQuery easyUI id选择器 类选择器 标签选择器 属性选择器 及DOM对象和jQuery相互之间的转换
- lynis检测
- Boost多线程