springmvc 搭建 注解方式
以用户登录为例简单介绍使用注解方式实现springmvc的过程。
一、代码目录结构:
二、在web.xml中配置前端页面控制器,动态添加spring容器
三、配置spring.xml设置spring容器,开启自动扫描(context:component-scan)、mvc注解(mvc:annotation)、配置视图解析器(InternalResourceViewResolver)
四、书写登录页面,页面分两部分,使用单个参数及使用对象作为参数传递
五、书写跳转成功后的页面
六、编写控制器,在控制器类上添加@Controller,方法是使用@RequestMapping("xx")指定方位路径,@RequestMapping("xx")也可添加在类上,方法上做子路径。
使用http://localhost:8080/springmvcanotation/login访问登录页面