1、使用注解减少配置xml文件

2、注解可以降低耦合度

3、使用注解编写的普通类

import javax.servlet.http.HttpServletRequest;

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

//说明springMvc controller 类
@Controller
public class testAction {

//设置请求路径
//返回值需要使用HttpServletRequest 这个有点不爽
@RequestMapping("/test")
public String test(HttpServletRequest request) {
request.setAttribute("test", "你妹");
return "/test";
}
}

4、spring 配置文件简单配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<!-- 注解扫描包 也就是指定controller 所在的包-->
<context:component-scan base-package="com.ly.action" /> <!-- 开启注解 -->
<mvc:annotation-driven /> <!-- 指明前缀和后缀 -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
</beans>

SpingMvc 注解的使用的更多相关文章

  1. SpingMVC注解式开发-处理器方法的参数(形参request等)

    HttpServletRequest HttpServletResponse HttpSession 请求中所携带的请求参数

  2. jQuery ajax的提交

    1.利用jQuery中的aja提交数据,首先引入jQuery中的文件 2.jquery.form.js下载地址:http://vdisk.weibo.com/s/thY_x31gX0M-p?categ ...

  3. Spring3+SpingMVC+Hibernate4全注解环境配置

    Spring3+SpingMVC+Hibernate4全注解环境配置 我没有使用maven,直接使用Eclipse创建动态Web项目,jar包复制在了lib下.这样做导致我马上概述的项目既依赖Ecli ...

  4. SpingMvc中的控制器的注解一般用那个,有没有别的注解可以替代?

    答:一般用@Controller注解,也可以使用@RestController,@RestController注解相当于@ResponseBody + @Controller,表示是表现层,除此之外, ...

  5. SpingMvc中的异常处理

    一.处理异常的方式      Spring3.0中对异常的处理方法一共提供了两种: 第一种是使用HandlerExceptionResolver接口. 第二种是在Controller类内部使用@Exc ...

  6. springMVC 注解版

    http://blog.csdn.net/liuxiit/article/details/5756115 http://blog.csdn.net/hantiannan/article/categor ...

  7. SSM框架中常用的注解

    @Controller:在SpringMVC 中,控制器Controller 负责处理由DispatcherServlet 分发的请求,它把用户请求的数据经过业务处理层处理之后封装成一个Model , ...

  8. SpingMVC的工作流程

    一.SpringMVC的主要组件 前端控制器(DisatcherServlet):接收请求,响应结果,返回可以是json,String等数据类型,也可以是页面(Model). 处理器映射器(Handl ...

  9. spingMVC异步上传文件

    框架是个强大的东西,一般你能想到的,框架都会帮你做了,然后只需要会用就行了,spingmvc中有处理异步请求的机制,而且跟一般处理请求的方法差别不大,只是多了一个注解:spingmvc也可以将stri ...

随机推荐

  1. 如何获取path与basePath

    <%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding=& ...

  2. Simple But Useful Samples About 'grep' Command(简单实用的grep 命令)

    Do the following: grep -rnw '/path/to/somewhere/' -e "pattern" -r or -R is recursive, -n i ...

  3. SqlMapClient ,SqlExecutor 和SqlMapClientTemplate 的区别?

    SqlMapClient SqlExecutor SqlMapClientTemplate

  4. const与static的区别

    const就是只读的意思,只在声明中使用;const修饰的数据类型是指常类型,常类型的变量或对象的值是不能被更新的. const的作用: (1)可以定义const常量,具有不可变性. (2)便于进行类 ...

  5. 转:HTTP协议详解(真的很经典)

    转自:http://blog.csdn.net/gueter/archive/2007/03/08/1524447.aspx Author :Jeffrey 引言 HTTP是一个属于应用层的面向对象的 ...

  6. linux下安装rabbitmq

    1.安装erlang虚拟机 Rabbitmq基于erlang语言开发,所有需要安装erlang虚拟机.安装erlang有两种方式: 第一种:使用yum安装: wget -O /etc/yum.repo ...

  7. Android Studio的使用(十三)--设置方法分割线

    1.只需要在设置中选中show method separators 即可.

  8. Mysql命令-求一列字段的总和

    求和命令 mysql> select SUM(price) from order where create_time>'2016-03-12';+------------+| SUM(pr ...

  9. 看unix高级编程时遇到apue.h找不到的问题

    最近学习 Unix 环境高级编程这本书,第一个例子就碰到了问题,下面是解决办法. 一开始看到这本书,刚翻了几页,就觉得对味.按照书中的代码做练习时,编译代码文件提示fatal error: apue. ...

  10. Android tcpdump抓包应用实现

    Android tcpdump抓包应用实现   Android应用很多时候都会涉及到网络,在请求网络出错时,我们可以通过抓包来分析网络请求,返回的数据等,通常我们是用tcpdump这个工具来抓包,再通 ...