上一篇博客:SpringMVC初步介绍中的案例是以普通方式实现的,这样实现起来比较繁琐,下面我们来看看用注解的方式来实现
1、修改xml配置文件
<?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:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">
<!-- 开启springMvc注解 -->
<!-- 会自动注册DefaultAnnottationHandlerMapping与annottationMethodHandlerAdapter两个bean -->
<mvc:annotation-driven></mvc:annotation-driven>
<!-- 开启包扫描 -->
<context:component-scan base-package="com.zhouym.user