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. Note: Improving Restore Speed for Backup Systems that Use Inline Chunk-Based Deduplication

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

  2. Mysql索引优化1

    Btree索引和哈希索引(索引是一种数据结构,提高查询,排序,分组速度) Btree索引的数据结构是平衡二叉树,时间复杂度为lgN 哈希索引的数据结构是一个Hash函数,时间复杂度为O(1),数据输入 ...

  3. java知识点积累(二)

    4.条件运算符(三元运算符): String type = score<60?"不及格":"及格"; int i = (string=="hel ...

  4. java解析xml文件练习——通过应用包名获取应用图标即其他信息(基于魅族应用商店)

    1.解析包名数据文件(txt文件),并生成包名数组: package jsouphtml; import java.io.BufferedReader; import java.io.File; im ...

  5. LeetCode.11-装水最多的容器(Container With Most Water)

    这是悦乐书的第350次更新,第375篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Medium级别的第5题(顺位题号是11).给定n个非负整数a1,a2,-,an,其中每个表示坐标(i ...

  6. 不建议使用Restsharp

    Restsharp确实是个优秀的插件,它最大的特点是内置了JsonConverter, 在一定程度上简化了HttpWebRequest的使用,在nuget上面有19.3M的下载量,是个很好的证明. 但 ...

  7. thinphp5会员注册邮箱验证

    1.首先完成邮箱发送http://www.cnblogs.com/jcydd/p/7299750.html 2.在完成会员新增后执行后置函数,在模型类当中 //注册后置函数 protected sta ...

  8. java怎样防止内存溢出

    引起内存溢出的原因有很多种,小编列举一下常见的有以下几种: 1.内存中加载的数据量过于庞大,如一次从数据库取出过多数据:2.集合类中有对对象的引用,使用完后未清空,使得JVM不能回收:3.代码中存在死 ...

  9. vue中比较完美请求的栗子(使用 axios 访问 API)

    vue中比较完美请求的栗子(使用 axios 访问 API) 官网地址:https://vuejs.bootcss.com/v2/cookbook/using-axios-to-consume-api ...

  10. Caused by: MetaException(message:Hive Schema version 2.1.0 does not match metastore's schema version 1.2.0 Metastore is not upgraded or corrupt)_2

    Caused by: MetaException(message:Hive Schema version 2.1.0 does not match metastore's schema version ...