- 浏览: 575848 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (411)
- webservice (3)
- oracle (37)
- sqlserver (8)
- j2ee (56)
- linux (7)
- javaweb (47)
- office (1)
- struts (23)
- hibernate (11)
- spring (29)
- 网络 (2)
- tomcat (13)
- tongweb (0)
- weblogic (0)
- powerdesiginer (3)
- svn (3)
- js (20)
- ie (2)
- 编译 (3)
- css (2)
- 操作系统 (5)
- Android (41)
- jbpm4.3 (1)
- fckeditor (3)
- 操作excel (2)
- db2常用命令 (1)
- ibatis (5)
- mysql (16)
- 表达式语言 (1)
- java方式调用存储过程 (1)
- ca (1)
- linux客户端 (1)
- 电子数码 (1)
- 行业应用 (12)
- 开发工具 (4)
- 面试 (1)
- 计算机原理 (1)
- NOSQL (5)
- 虚拟机 (1)
- nginx (0)
- velocity (2)
- jndi (1)
- spring mvc (39)
- springmvc (32)
- 安全 (5)
- htmleditor (6)
- iphone4 (1)
- html (4)
- jstl (2)
- ckeditor (5)
- 连接池 (1)
- jquery (6)
- 分页 (1)
- 技术研发规则 (1)
- javamail (1)
- maven (2)
- upload (1)
- log (1)
- 测试 (10)
- spring roo (1)
- 版本控制 (2)
- find bugs (0)
- jsf (0)
- springroo (0)
- 小道理 (1)
- 小道理,技术标准 (1)
- jsf (0)
- bitbao (2)
- redmine (3)
- 团队意识 (1)
- mybatis (2)
- jquery mobile (1)
- flexpaper (0)
- json (4)
- URLRewriteFilte (1)
- html5 (1)
- 都乐保活动 (0)
- openfire (0)
- TreeMap (1)
- build (0)
- javaweb,tag (0)
- algorithm (1)
- tag (2)
- 扯淡 (0)
- mac (2)
- 叶一火(老一) (1)
- 游玩 (1)
- 编码 (1)
- 上线部署 (0)
- 研发管理 (0)
- thumbnailator (2)
- 旅游 (0)
- bingweibo (1)
- 杂谈 (4)
- ktv (1)
- weibo (1)
- 爱情 (2)
- 饮食 (1)
- MediaWiki (1)
- git (1)
- 版本库 (1)
- servlet (1)
- 感悟 (1)
- 人生 (1)
- highcharts (1)
- poi (0)
- websphere (0)
- php (1)
最新评论
-
woshixushigang:
good
org.springframework.beans.TypeMismatchException: Failed to convert property valu -
nathanleewei:
org.springframework.jdbc.core.B ...
org.springframework.beans.TypeMismatchException: Failed to convert property valu -
浪禾木:
请问是ckeditor\contents.css吗?改过以后 ...
ckeditor自动换行问题 -
simusuishi:
刚哥威武!
ckeditor取值赋值问题 -
a455642158:
收割完毕……
Android开源项目源码下载(不断更新中)
- /blog/ 1 HTTP GET => 得到id = 1 的blog
- /blog/1 HTTP DELETE => 删除 id = 1 的blog
- /blog/1 HTTP PUT => 更新id = 1 的blog
- /blog HTTP POST => 新增BLOG
首先,我们带着如下三
个问题
查看本文。
1.
如何在java构造没有扩展名的RESTful url,如 /forms/1,而不是 /forms/1.do
2. 由于我们要构造没有扩展名的url本来是处理静态资源的容器映射的,现在被我们的spring占用了,冲突怎么解决?
3. 浏览器的form标签不支持提交delete,put请求,如何曲线解决?
spring mvc rest 实现
spring mvc的resturl是通过@RequestMapping 及@PathVariable
annotation提供的,通过如@RequestMapping(value="/blog/{id}",method=RequestMethod.DELETE)即可处理/blog/1
的delete请求.
- @RequestMapping (value= "/blog/{id}" ,method=RequestMethod.DELETE)
- public ModelAndView delete( @PathVariable Long id,HttpServletRequest request,HttpServletResponse response) {
- blogManager.removeById(id);
- return new ModelAndView(LIST_ACTION);
- }
@RequestMapping(value="/blog/{id}",method=RequestMethod.DELETE) public ModelAndView delete(@PathVariable Long id,HttpServletRequest request,HttpServletResponse response) { blogManager.removeById(id); return new ModelAndView(LIST_ACTION); }
@RequestMapping @PathVariable如果URL中带参数,则配合使用,如
- @RequestMapping (value= "/blog/{blogId}/message/{msgId}" ,method=RequestMethod.DELETE)
- public ModelAndView delete( @PathVariable ( "blogId" ) Long blogId, @PathVariable ( "msgId" ) Long msgId,HttpServletRequest request,HttpServletResponse response) {
- }
@RequestMapping(value="/blog/{blogId}/message/{msgId}",method=RequestMethod.DELETE) public ModelAndView delete(@PathVariable("blogId") Long blogId,@PathVariable("msgId") Long msgId,HttpServletRequest request,HttpServletResponse response) { }
spring rest配置指南
1. spring mvc web.xml配置
- <!-- 该servlet为tomcat,jetty等容器提供,将静态资源映射从/改为/static/目录,如原来访问 http://localhost/foo.css ,现在http://localhost/static/foo.css -->
- < servlet-mapping >
- < servlet-name > default </ servlet-name >
- < url-pattern > /static/* </ url-pattern >
- </ servlet-mapping >
- < servlet >
- < servlet-name > springmvc </ servlet-name >
- < servlet-class > org.springframework.web.servlet.DispatcherServlet </ servlet-class >
- < load-on-startup > 1 </ load-on-startup >
- </ servlet >
- <!-- URL重写filter,用于将访问静态资源http://localhost/foo.css 转为http://localhost/static/foo.css -->
- < filter >
- < filter-name > UrlRewriteFilter </ filter-name >
- < filter-class > org.tuckey.web.filters.urlrewrite.UrlRewriteFilter </ filter-class >
- < init-param >
- < param-name > confReloadCheckInterval </ param-name >
- < param-value > 60 </ param-value >
- </ init-param >
- < init-param >
- < param-name > logLevel </ param-name >
- < param-value > DEBUG </ param-value >
- </ init-param >
- </ filter >
- < filter-mapping >
- < filter-name > UrlRewriteFilter </ filter-name >
- < url-pattern > /* </ url-pattern >
- </ filter-mapping >
- <!-- 覆盖default servlet的/, springmvc servlet将处理原来处理静态资源的映射 -->
- < servlet-mapping >
- < servlet-name > springmvc </ servlet-name >
- < url-pattern > / </ url-pattern >
- </ servlet-mapping >
- <!-- 浏览器不支持put,delete等method,由该filter将/blog?_method=delete转换为标准的http delete方法 -->
- < filter >
- < filter-name > HiddenHttpMethodFilter </ filter-name >
- < filter-class > org.springframework.web.filter.HiddenHttpMethodFilter </ filter-class >
- </ filter >
- < filter-mapping >
- < filter-name > HiddenHttpMethodFilter </ filter-name >
- < servlet-name > springmvc </ servlet-name >
- </ filter-mapping >
<!-- 该servlet为tomcat,jetty等容器提供,将静态资源映射从/改为/static/目录,如原来访问 http://localhost/foo.css ,现在http://localhost/static/foo.css --> <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>/static/*</url-pattern> </servlet-mapping> <servlet> <servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <!-- URL重写filter,用于将访问静态资源http://localhost/foo.css 转为http://localhost/static/foo.css --> <filter> <filter-name>UrlRewriteFilter</filter-name> <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class> <init-param> <param-name>confReloadCheckInterval</param-name> <param-value>60</param-value> </init-param> <init-param> <param-name>logLevel</param-name> <param-value>DEBUG</param-value> </init-param> </filter> <filter-mapping> <filter-name>UrlRewriteFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- 覆盖default servlet的/, springmvc servlet将处理原来处理静态资源的映射 --> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <!-- 浏览器不支持put,delete等method,由该filter将/blog?_method=delete转换为标准的http delete方法 --> <filter> <filter-name>HiddenHttpMethodFilter</filter-name> <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class> </filter> <filter-mapping> <filter-name>HiddenHttpMethodFilter</filter-name> <servlet-name>springmvc</servlet-name> </filter-mapping>
2. webapp/WEB-INF/springmvc-servlet.xml配置,使用如下两个class激活@RequestMapping annotation
- <bean class = "org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
- <bean class = "org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/> <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>
完整配置
- <beans default -autowire= "byName" >
- <!-- 自动搜索@Controller 标注的类 -->
- <context:component-scan base-package = "com.**.controller" />
- <bean class = "org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
- <bean class = "org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
- <!-- Default ViewResolver -->
- <bean id="viewResolver" class = "org.springframework.web.servlet.view.InternalResourceViewResolver" >
- <property name="viewClass" value= "org.springframework.web.servlet.view.JstlView" />
- <property name="prefix" value= "/pages" />
- <property name="suffix" value= ".jsp" ></property>
- </bean>
- <bean id="messageSource" class = "org.springframework.context.support.ResourceBundleMessageSource" p:basename= "i18n/messages" />
- <!-- Mapping exception to the handler view -->
- <bean id="exceptionResolver" class = "org.springframework.web.servlet.handler.SimpleMappingExceptionResolver" >
- <!-- to /commons/error.jsp -->
- <property name="defaultErrorView" value= "/commons/error" />
- <property name="exceptionMappings" >
- <props>
- </props>
- </property>
- </bean>
- </beans>
<beans default-autowire="byName" > <!-- 自动搜索@Controller标注的类 --> <context:component-scan base-package="com.**.controller"/> <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/> <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/> <!-- Default ViewResolver --> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> <property name="prefix" value="/pages"/> <property name="suffix" value=".jsp"></property> </bean> <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource" p:basename="i18n/messages"/> <!-- Mapping exception to the handler view --> <bean id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"> <!-- to /commons/error.jsp --> <property name="defaultErrorView" value="/commons/error"/> <property name="exceptionMappings"> <props> </props> </property> </bean> </beans>
3. Controller编写
- /**
- * @RequestMapping("/userinfo") 具有层次关系,方法级的将在类一级@RequestMapping之一,
- * 如下面示例, 访问方法级别的@RequestMapping("/new"),则URL为 /userinfo/new
- */
- @Controller
- @RequestMapping ( "/userinfo" )
- public class UserInfoController extends BaseSpringController{
- //默认多列排序,example: username desc,createTime asc
- protected static final String DEFAULT_SORT_COLUMNS = null ;
- private UserInfoManager userInfoManager;
- private final String LIST_ACTION = "redirect:/userinfo" ;
- /**
- * 通过spring自动注入
- **/
- public void setUserInfoManager(UserInfoManager manager) {
- this .userInfoManager = manager;
- }
- /** 列表 */
- @RequestMapping
- public ModelAndView index(HttpServletRequest request,HttpServletResponse response,UserInfo userInfo) {
- PageRequest<Map> pageRequest = newPageRequest(request,DEFAULT_SORT_COLUMNS);
- //pageRequest.getFilters(); //add custom filters
- Page page = this .userInfoManager.findByPageRequest(pageRequest);
- savePage(page,pageRequest,request);
- return new ModelAndView( "/userinfo/list" , "userInfo" ,userInfo);
- }
- /** 进入新增 */
- @RequestMapping (value= "/new" )
- public ModelAndView _new(HttpServletRequest request,HttpServletResponse response,UserInfo userInfo) throws Exception {
- return new ModelAndView( "/userinfo/new" , "userInfo" ,userInfo);
- }
- /** 显示 */
- @RequestMapping (value= "/{id}" )
- public ModelAndView show( @PathVariable Long id,HttpServletRequest request,HttpServletResponse response) throws Exception {
- UserInfo userInfo = (UserInfo)userInfoManager.getById(id);
- return new ModelAndView( "/userinfo/show" , "userInfo" ,userInfo);
- }
- /** 编辑 */
- @RequestMapping (value= "/{id}/edit" )
- public ModelAndView edit( @PathVariable Long id,HttpServletRequest request,HttpServletResponse response) throws Exception {
- UserInfo userInfo = (UserInfo)userInfoManager.getById(id);
- return new ModelAndView( "/userinfo/edit" , "userInfo" ,userInfo);
- }
- /** 保存新增 */
- @RequestMapping (method=RequestMethod.POST)
- public ModelAndView create(HttpServletRequest request,HttpServletResponse response,UserInfo userInfo) throws Exception {
- userInfoManager.save(userInfo);
- return new ModelAndView(LIST_ACTION);
- }
- /** 保存更新 */
- @RequestMapping (value= "/{id}" ,method=RequestMethod.PUT)
- public ModelAndView update( @PathVariable Long id,HttpServletRequest request,HttpServletResponse response) throws Exception {
- UserInfo userInfo = (UserInfo)userInfoManager.getById(id);
- bind(request,userInfo);
- userInfoManager.update(userInfo);
- return new ModelAndView(LIST_ACTION);
- }
- /** 删除 */
- @RequestMapping (value= "/{id}" ,method=RequestMethod.DELETE)
- public ModelAndView delete( @PathVariable Long id,HttpServletRequest request,HttpServletResponse response) {
- userInfoManager.removeById(id);
- return new ModelAndView(LIST_ACTION);
- }
- /** 批量删除 */
- @RequestMapping (method=RequestMethod.DELETE)
- public ModelAndView batchDelete( @RequestParam ( "items" ) Long[] items,HttpServletRequest request,HttpServletResponse response) {
- for ( int i = 0 ; i < items.length; i++) {
- userInfoManager.removeById(items[i]);
- }
- return new ModelAndView(LIST_ACTION);
- }
- }
/** * @RequestMapping("/userinfo") 具有层次关系,方法级的将在类一级@RequestMapping之一, * 如下面示例, 访问方法级别的@RequestMapping("/new"),则URL为 /userinfo/new */ @Controller @RequestMapping("/userinfo") public class UserInfoController extends BaseSpringController{ //默认多列排序,example: username desc,createTime asc protected static final String DEFAULT_SORT_COLUMNS = null; private UserInfoManager userInfoManager; private final String LIST_ACTION = "redirect:/userinfo"; /** * 通过spring自动注入 **/ public void setUserInfoManager(UserInfoManager manager) { this.userInfoManager = manager; } /** 列表 */ @RequestMapping public ModelAndView index(HttpServletRequest request,HttpServletResponse response,UserInfo userInfo) { PageRequest<Map> pageRequest = newPageRequest(request,DEFAULT_SORT_COLUMNS); //pageRequest.getFilters(); //add custom filters Page page = this.userInfoManager.findByPageRequest(pageRequest); savePage(page,pageRequest,request); return new ModelAndView("/userinfo/list","userInfo",userInfo); } /** 进入新增 */ @RequestMapping(value="/new") public ModelAndView _new(HttpServletRequest request,HttpServletResponse response,UserInfo userInfo) throws Exception { return new ModelAndView("/userinfo/new","userInfo",userInfo); } /** 显示 */ @RequestMapping(value="/{id}") public ModelAndView show(@PathVariable Long id,HttpServletRequest request,HttpServletResponse response) throws Exception { UserInfo userInfo = (UserInfo)userInfoManager.getById(id); return new ModelAndView("/userinfo/show","userInfo",userInfo); } /** 编辑 */ @RequestMapping(value="/{id}/edit") public ModelAndView edit(@PathVariable Long id,HttpServletRequest request,HttpServletResponse response) throws Exception { UserInfo userInfo = (UserInfo)userInfoManager.getById(id); return new ModelAndView("/userinfo/edit","userInfo",userInfo); } /** 保存新增 */ @RequestMapping(method=RequestMethod.POST) public ModelAndView create(HttpServletRequest request,HttpServletResponse response,UserInfo userInfo) throws Exception { userInfoManager.save(userInfo); return new ModelAndView(LIST_ACTION); } /** 保存更新 */ @RequestMapping(value="/{id}",method=RequestMethod.PUT) public ModelAndView update(@PathVariable Long id,HttpServletRequest request,HttpServletResponse response) throws Exception { UserInfo userInfo = (UserInfo)userInfoManager.getById(id); bind(request,userInfo); userInfoManager.update(userInfo); return new ModelAndView(LIST_ACTION); } /** 删除 */ @RequestMapping(value="/{id}",method=RequestMethod.DELETE) public ModelAndView delete(@PathVariable Long id,HttpServletRequest request,HttpServletResponse response) { userInfoManager.removeById(id); return new ModelAndView(LIST_ACTION); } /** 批量删除 */ @RequestMapping(method=RequestMethod.DELETE) public ModelAndView batchDelete(@RequestParam("items") Long[] items,HttpServletRequest request,HttpServletResponse response) { for(int i = 0; i < items.length; i++) { userInfoManager.removeById(items[i]); } return new ModelAndView(LIST_ACTION); } }
上面是rapid-framework新版本生成器生成的代码,以后也将应用此规则,rest url中增删改查等基本方法与Controller的方法映射规则
- /userinfo => index()
- /userinfo/new => _new()
- /userinfo/{id} => show()
- /userinfo/{id}/edit => edit()
- /userinfo POST => create()
- /userinfo/{id} PUT => update()
- /userinfo/{id} DELETE => delete()
- /userinfo DELETE => batchDelete()
/userinfo => index() /userinfo/new => _new() /userinfo/{id} => show() /userinfo/{id}/edit => edit() /userinfo POST => create() /userinfo/{id} PUT => update() /userinfo/{id} DELETE => delete() /userinfo DELETE => batchDelete()
注(不使用 /userinfo/add => add() 方法是由于add这个方法会被maxthon浏览器当做广告链接过滤掉,因为包含ad字符)
4. jsp 编写
- < form:form action = "${ctx}/userinfo/${userInfo.userId}" method = "put" >
- </ form:form >
<form:form action="${ctx}/userinfo/${userInfo.userId}" method="put"> </form:form>
生成的html内容如下, 生成一个hidden的_method=put,并于web.xml中的HiddenHttpMethodFilter配合使用,在服务端将post请求改为put请求
- <form id= "userInfo" action= "/springmvc_rest_demo/userinfo/2" method= "post" >
- <input type="hidden" name= "_method" value= "put" />
- </form>
<form id="userInfo" action="/springmvc_rest_demo/userinfo/2" method="post"> <input type="hidden" name="_method" value="put"/> </form>
另外一种方法是你可以使用ajax发送put,delete请求.
5. 静态资源的URL重写
如上我们描述,现因为将default servlet映射至/static/的子目录,现我们访问静态资源将会带一个/static/前缀.
如 /foo.gif, 现在访问该文件将是 /static/foo.gif.
那如何避免这个前缀呢,那就是应用URL
rewrite,现我们使用 http://tuckey.org/urlrewrite/
,
重写规则如下
- < urlrewrite >
- <!-- 访问jsp及jspx将不rewrite url,其它.js,.css,.gif等将重写,如 /foo.gif => /static/foo.gif -->
- < rule >
- < condition operator = "notequal" next = "and" type = "request-uri" > .*.jsp </ condition >
- < condition operator = "notequal" next = "and" type = "request-uri" > .*.jspx </ condition >
- < from > ^(/.*\..*)$ </ from >
- < to > /static$1 </ to >
- </ rule >
- </ urlrewrite >
发表评论
-
RESTFUL
2013-05-29 17:21 0a -
hibernate命名查询问题
2013-01-30 16:38 1314hibernate 注解 @OneToOne(fetc ... -
hibernate [Null value was assigned to a property of primitive type setter of sco
2012-12-25 19:51 1113今天开发时候 hibernate 查询报错,分析原因如下: ... -
Arrays.asList详解
2012-09-10 09:52 885Arrays.asList详解 记得以前写过一 ... -
mapper.readValue读取null
2012-08-17 19:21 2583如下代码,这样写不会走catch方法,此方法不报ioExcep ... -
string.split(",")返回的长度问题
2012-08-17 15:38 910String test = "#我的测试#&q ... -
thumbnailator 图片缩放问题
2012-08-17 19:29 2745这段代码上传1.7m图片会报错: publ ... -
模拟微博新鲜事短网址处理方式
2012-08-16 17:40 0a -
新鲜事短连接
2012-08-19 12:01 954现在需求如下: 使 ... -
jackson objectMapper.readValue 读取并存成想要的类型
2012-07-26 20:16 3700两种方式: java反射里面有个很有趣的东东,反射解析成li ... -
spring mvc responseBody 会把特殊字符转义
2012-07-26 19:53 4503框架用的spring 采用spring mvc 方式进行图片上 ... -
Out of range value for column 'bindUid' at row 1
2012-07-19 20:35 1490今天弄新浪微博绑定,数据库oauth_token表需要插入bi ... -
spring mvc 自己遇到的几个错误
2012-06-13 14:36 1197where 1=1 and t.name like '%&q ... -
Request method 'POST' not supported
2012-06-08 10:53 5202项目采用spring mvc框架实现,插入数据时候采用 ... -
beanPropertyRowMapper
2012-08-10 11:24 1076@SuppressWarnings(&quo ... -
org.codehaus.jackson.map.JsonMappingException
2012-08-17 19:30 981当一个类的所有属性都没有getter时(所有属性都是publi ... -
validApiToken
2012-08-10 11:26 971/** * 检验token的有效性 * @p ... -
split
2012-05-23 10:46 1195//String[] idArr = StringUtil ... -
spring mvc title展示的几种写法
2012-05-18 17:16 1087我记录的是工作中遇到的,容易忽视的问题,高手可以绕行了。积累也 ... -
c:import src="" jsp页面同步方式获取数据
2012-05-14 11:28 1079可以把页面分割成不同的几块,同步方式获取数据。即分别调用 ...
相关推荐
在本文中,我们将深入探讨如何利用Spring MVC创建RESTful服务,这些服务可以处理字符串、JSON和XML数据,并且是用Maven构建的。我们将讨论关键概念、配置、以及如何构建可直接运行的项目。 1. **RESTful服务**:...
**Spring MVC RESTful接口实例详解** Spring MVC 是一个强大的Java Web框架,用于构建基于模型-视图-控制器(MVC)架构的Web应用程序。RESTful是Representational State Transfer的缩写,是一种网络应用程序的设计...
本书共计10章,分别介绍了快速搭建Spring Web应用、精通MVC结构、URL映射、文件上传与错误处理、创建Restful应用、保护应用、单元测试与验收测试、优化请求、将Web应用部署到云等内容,循序渐进地讲解了Spring MVC4...
在本文中,我们将深入探讨如何在Spring 3.0中整合MVC框架与RESTful服务,并结合Maven构建项目。RESTful(Representational State Transfer)是一种软件架构风格,用于设计网络应用程序,尤其适用于Web服务。Spring ...
Spring 3 MVC框架是Java开发者广泛使用的构建Web应用的工具,它为开发RESTful API提供了强大的支持。本教程将深入探讨如何利用Spring 3 MVC实现RESTful服务。 首先,理解REST的基本原则至关重要。RESTful架构有以下...
这通常包括Spring MVC的核心库,如spring-webmvc,以及与RESTful相关的库,例如Jackson或Gson用于JSON序列化和反序列化,还有可能包含Spring Boot Starter Web,简化了Spring MVC和RESTful的集成。 在标签中,"java...
除此之外,教程可能还会涵盖Spring MVC的RESTful API设计,如何创建JSON响应,以及使用Spring Boot快速构建Spring MVC应用。Spring Boot简化了配置,提供了预配置的依赖,使得开发者能更快地启动项目。 错误处理和...
Spring MVC是Spring框架的一个核心模块,专为构建Web应用程序提供模型-视图-控制器(MVC)架构。在Spring MVC 4.0版本中,它引入了许多改进和新特性,以提升开发效率和应用程序的性能。 1. **依赖注入**:Spring ...
综上所述,这个整合架构提供了一种高效的Web开发模式,Spring3 MVC处理后端逻辑,RESTful设计优化了接口,FreeMarker生成动态页面,jQuery简化了前端交互,而JSON则作为数据交换的桥梁。这样的组合能够帮助开发者...
在Spring 3.0框架中,Spring MVC是一个强大的用于构建Web应用程序的模块,它支持构建RESTful风格的URL,使得应用程序更加符合Web服务的最佳实践。REST(Representational State Transfer)是一种设计模式,强调通过...
此外,Spring MVC 4还支持RESTful风格的Web服务,通过@RequestMapping注解的produces和consumes属性,可以处理不同格式的HTTP请求和响应,如JSON、XML等。 总的来说,"Mastering Spring MVC 4(2015.09)源码"提供了...
本教程将通过一个名为"spring-mvc-demo"的项目,详细介绍如何使用Spring框架来实现RESTful Web服务。 一、Spring MVC与RESTful Web服务 Spring MVC是Spring框架的一部分,专门用于处理Web请求和响应。RESTful Web...
12. **RESTful**: Spring MVC支持RESTful Web服务,通过HTTP动词(GET、POST、PUT、DELETE等)和URI结构来创建无状态、客户端驱动的接口。 13. **Spring Data Access**: Spring MVC可以与Spring Data、Hibernate、...
14. **RESTful API**:Spring MVC通过`@RestController`和`@RequestMapping`可以轻松创建RESTful风格的API,便于前后端分离的开发。 15. **Spring MVC的配置**:包括XML配置和Java配置两种方式,现在更推荐使用Java...
@RequestParam用于获取URL查询参数,@PathVariable用于处理RESTful风格的URL,@RequestBody用于接收JSON或XML格式的请求体。 4. **视图解析:ViewResolver** 视图解析器如InternalResourceViewResolver负责根据...
Spring MVC 是一款基于Java的轻量级Web应用框架,它为构建RESTful应用程序提供了强大的支持。这个"Spring MVC 简单Demo"旨在帮助初学者理解如何设置和运行一个基本的Spring MVC项目。下面,我们将深入探讨Spring MVC...
6. **RESTful风格的URL设计**: Spring MVC支持创建符合REST原则的URL,便于构建基于HTTP的API。例如,使用`@GetMapping`、`@PostMapping`等注解来映射HTTP的GET、POST等方法。 7. **参数绑定**: Spring MVC可以自动...
Spring 4引入了更多的注解,如`@RestController`(用于RESTful服务)、`@PathVariable`(用于处理URL路径变量)、`@RequestParam`(用于处理请求参数)等,这使得代码更加简洁,降低了XML配置的复杂性。 7. **...