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;
}
}

springMvc-reset风格和对静态资源的管理的更多相关文章

  1. SpringMVC 表单标签 & 处理静态资源

    使用 Spring 的表单标签 通过 SpringMVC 的表单标签可以实现将模型数据中的属性和 HTML 表单元素相绑定,以实现表单数据更便捷编辑和表单值的回显. form 标签 一般情况下,通过 ...

  2. SpringMVC 拦截器不拦截静态资源的三种处理方式

    SpringMVC提供<mvc:resources>来设置静态资源,但是增加该设置如果采用通配符的方式增加拦截器的话仍然会被拦截器拦截,可采用如下方案进行解决: 方案一.拦截器中增加针对静 ...

  3. springmvc获取jar中的静态资源与jar包中的资源互相引用问题

    1.首先看jar中的文件位置 2.在web工程中引用该jar 并且在springmvc文件中配置路径 如果有多个路径可用逗号隔开 3.在web工程找jsp页面如何引用 这样就可以了 关于jar中的资源 ...

  4. springmvc 请求经过controller后静态资源无法访问的问题

    经过RequestMapping(“xx”)后 转发请求时会在url里面附带地址, 导致访问静态资源文件失败, 解决办法是在 spring-mvc.xml文件中加上 <mvc:default-s ...

  5. SpringMVC 拦截器不拦截静态资源的三种处理方式方法

    方案一.拦截器中增加针对静态资源不进行过滤(涉及spring-mvc.xml) <mvc:resources location="/" mapping="/**/* ...

  6. SpringMVC听课笔记(SpringMVC 表单标签 & 处理静态资源)

    1.springmvc表单标签,可以快速开发,表单回显,但是感触不深 2.静态资源的获取,主要是要配置这个

  7. SpringMVC -- 梗概--源码--贰--静态资源的访问问题

    配置:<mvc:default-servlet-handler/> 1>静态资源:除了Servlet.Controller之外的资源,如:js,css,png,html等 2> ...

  8. SpringMVC中静态资源的处理

    web项目中web.xml配置 在一个使用springmvc的web项目中,必然在web.xml中要配置前端控制器DispatcherServlet <servlet> <servl ...

  9. springMVC servlet 静态资源加载

    问题描述 新手使用SpringMVC时市场会遇到静态资源无法加载在问题,如下图所示 问题原因 出现这种问题一般是在web.xml中的对spring的DispatcherServlet采用了如下配置,即 ...

随机推荐

  1. centos运行netcore error:package: ‘Microsoft.AspNetCore.Antiforgery‘, version: ‘2.0.3‘

    Error: An assembly specified in the application dependencies manifest (*.*.deps.json) was not found: ...

  2. C#中的自动属性、隐式类型var、对象初始化器与集合初始化器、扩展方法

    1.自动属性(Auto-Implemented Properties) //以前的写法 .net2.0 private string _userName; public string UserName ...

  3. Note: Improving Restore Speed for Backup Systems that Use Inline Chunk-Based Deduplication

    思路/方法 Measuring restore speed 提出了speed-factor,用以衡量存储速度. Container capping 限制恢复文件时使用的container个数,为了保证 ...

  4. Vue.js 源码实现

    目录 Vue.js 代码实现 1. 步骤一 2. 步骤二 3.步骤三 Vue.js 工作机制 初始化 编译 响应式 虚拟dom 更新视图 编译 Vue.js 代码实现 检验学习效果的最好方法就是自己造 ...

  5. bzoj2055: 80人环游世界(可行流)

    传送门 表示完全看不懂最小费用可行流…… 据某大佬说 我们考虑拆点,然后进行如下连边 $s$向$a_i$连边,权值$0$,容量$[0,m]$ $a_i$向$a_i'$连边,权值$0$容量$[v_i,v ...

  6. 遍历json字符串 并 写入对应的文本框

    1.js代码: function getFlws(){ var url = urlpath + "bhjk/getJson2.sd?"; $.post(url,function(d ...

  7. P1168 中位数(对顶堆)

    题意:维护一个序列,两种操作 1.插入一个数 2.输出中位数(若长度为偶数,输出中间两个较小的那个) 对顶堆 维护一个小根堆,一个大根堆,大根堆存1--mid,小根堆存mid+1---n 这样堆顶必有 ...

  8. 低价购买 dp

    题目描述 “低价购买”这条建议是在奶牛股票市场取得成功的一半规则.要想被认为是伟大的投资者,你必须遵循以下的问题建议:“低价购买:再低价购买”.每次你购买一支股票,你必须用低于你上次购买它的价格购买它 ...

  9. linux下python3的安装(已安装python2的情况下)

    前段时间想自学一下python,就在虚拟机里已安装python2.7的情况下又安装了最新版python3.6.4.于是问题来了..只要一打开终端就出现一大段错误代码(忘记截图了),当时看到是ros和p ...

  10. Ubuntu下rsyslog审计用户bash操作命令、收集、写入MySQL

    服务端 2台服务端:10.25.109.64.10.45.18.133 1.rsyslog最新版本安装 sudo add-apt-repository ppa:adiscon/v8-stable su ...