SpringMVC的注解框架:

优点:

1.一个控制器类处理多个动作(如果实现了Controller,则不可以实现此方法)。

2.不需要配置到xml文件中,会造成xml文件非常的复杂 而且不利于分散式开发。

3.提高了灵活度


注解类主要分布:(还有其他注解、如service、resposity、autowire、quafiler、entity等)

Controller:注解:org.springframework.stereotype.Controller

RequestMapping:注解:org.springframework.web.bind.annotation.RequestMapping

例:@RequestMapping(param)

param:

value=“”;

“”

method={RequestMethod.POST/GET....}

(RequestMappingHandlerMapping、RequestMappingHandlerAdapter)开启映射


通过path的映射寻找不同的方法

@Autowired与@Service注解进行依赖注入

依赖注入->@Autowired注解进行依赖注入

@Service注解-指导一个service业务逻辑类


4.Spring 的扫描机制:

1.配置Spring-context->加入schema与名空间(Spring框架)

2.添加<context:componet-scan base-package=""/>

3.<mvc:annotation-drivern/>


5.重定向与Flash属性

1.转发比重定向快

2.转发不经过客户端、重定向经过客户端

3.转发可以定向到外部网络,比重定向好


6.请求参数与路径变量

1.RequestParam:request.getParameter()

2.PathVaribable:requestMapping(”/{paramName}“)—>@PathVariable ClassType paramName


7.ViewResolver直接进行解析视图的样式:

例子:jsp

<bean id = "jspViewResolver" class = " ......InternalResourceViewResolver">

<property name = "prefix" value = "/web-inf/jsp/"/>//转发前缀标识符

<property name = "suffix" value = ".jsp"/>

</bean>


8.页面传值:

1.ModelAndView对象的后端向前端传值;

2.ModelMap参数 实现方式ModelMap.model.addAttribute("","");

3.@ModelAttribute注解


9.重定向视图:

1.ReqirectView("") return 一个ModelAndView : new ModelAndView(new RedirectView(""))

2.redirect:"redirect:****"