Spring MVC:常用参数(注解)的使用和参数绑定的验证

一、学习资源

Java EE企业级应用开发教程(Spring+Spring MVC+MyBatis)(第2版)

在这里插入图片描述

二、基础源码

Spring MVC常用参数
Spring MVC简单应用
Spring MVC参数绑定

三、实验结果

3.1 Spring MVC常用参数

本实验采用的是本地安装的tomcat8.5.0版本

(1)创建maven 管理的java web工程
在这里插入图片描述
(2)添加本地tomcat
在这里插入图片描述

war包

在这里插入图片描述
(3)实验过程

输出Hello Word

在这里插入图片描述

访问端口:http://localhost:8080/chapter11/controller01
在这里插入图片描述

Spring MVC 常用注解

@Controller和@RequestMapping

实现自动寻找controller
访问端口:http://localhost:8080/chapter11/execute

在这里插入图片描述

@RequestMapping

访问端口: http://localhost:8080/chapter11/toWelcome

@RequestParam

访问端口: http://localhost:8080/chapter11/toLogin

在这里插入图片描述

在这里插入图片描述

@PathVariable

访问端口: http://localhost:8080/chapter11/claList/1/stuList/2

在这里插入图片描述

访问端口: http://localhost:8080/chapter11/claList/3/stuList/4
在这里插入图片描述

@Cookie Value

访问端口: http://localhost:8080/chapter11/testCookie

在这里插入图片描述

@RequestHeader

访问端口: http://localhost:8080/chapter11/testRequestHeader

在这里插入图片描述

3.2 Spring MVC参数绑定

本实验使用的为tomcat7.0版本
在源码文件的pom.xml中有配置插件

3.2.1 简单数据类型绑定

默认数据类型

访问端口:http://localhost:8080/findById
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

简单数据类型

在这里插入图片描述

绑定POJO类型

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

自定义数据类型

在这里插入图片描述

3.2.2 复杂数据类型绑定

(知道一点),此处前端值向后端传递没有成功

数组类型

在这里插入图片描述

集合类型

在这里插入图片描述

四、实验小结

本实验需要熟练使用maven和Tomcat,以及理解spring MVC参数使用;设计javaweb知识,需要回顾前后端值传递过程。

欢迎大家在评论区讨论交流,有时间就回。。。。
看到这里记得点赞+关注^^

猜你喜欢

转载自blog.csdn.net/m0_52331159/article/details/130648980