SpringMvc中的开启注释(整理)

来源:互联网 发布:js onclick传参 编辑:程序博客网 时间:2024/06/11 23:46
<pre name="code" class="html"><?xml version="1.0" encoding="UTF-8"?>  <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc"xmlns:p="http://www.springframework.org/schema/p"    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.xingao.controller"/>   <!-- 开启注解 --><bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/><bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/><!-- 静态资源的访问 --><mvc:resources location="/img/" mapping="/img/**"/><mvc:resources location="/js/" mapping="/js/**"/><!-- 视图分解器 --><bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="prefix" value="/"/><property name="suffix" value=".jsp"/></bean><!-- 上传文件的解析器 --><bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"><property name="defaultEncoding" value="utf-8"/><property name="maxUploadSize" value="10485760000"/><property name="maxInMemorySize" value="40960"/></bean></beans>


以上是来自:http://blog.csdn.net/caochuankui/article/details/17389557

org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter
org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping
用处解析:
  1. <!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 -->  
  2. <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" lazy-init="false"/>  
  3. <!-- 另外最好还要加入DefaultAnnotationHandlerMapping,不然会被 XML或其它的映射覆盖!-->  
  4. <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />  

所谓的注释:

<pre name="code" class="java">package com.baobaotao.web;import com.baobaotao.service.BbtForumService;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.ModelAttribute;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import java.util.Collection;@Controller                   //<——①注释1@RequestMapping("/forum.do")public class BbtForumController {    @Autowired    private BbtForumService bbtForumService;    @RequestMapping //<——②注释2    public String listAllBoard() {        bbtForumService.getAllBoard();        System.out.println("call listAllBoard method.");        return "listBoard";    }}



0 0
原创粉丝点击