首页 技术 正文
技术 2022年11月9日
0 收藏 911 点赞 1,332 浏览 1929 个字

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

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,488
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,903
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,737
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,489
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,128
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,290