当前位置: 首页 > news >正文

曲靖做网站的公司建设购物网站多少钱

曲靖做网站的公司,建设购物网站多少钱,企业工商信息查询系统官网,沈阳免费做网站今天#xff0c;我想演示如何将AJAX集成到Spring MVC应用程序中。 我将在客户端使用JQuery来发送请求和接收响应。 本教程将基于我以前关于Spring MVC和REST服务的教程之一。 在本文中#xff0c;您将了解如何在异步请求的帮助下使Web应用程序更具交互性。 准备工作 我需要通… 今天我想演示如何将AJAX集成到Spring MVC应用程序中。 我将在客户端使用JQuery来发送请求和接收响应。 本教程将基于我以前关于Spring MVC和REST服务的教程之一。 在本文中您将了解如何在异步请求的帮助下使Web应用程序更具交互性。 准备工作 我需要通过删除不再需要的方法来修改SmartphoneController类。 这是AJAX集成的第一步。 //imports are omitted Controller RequestMapping(value/smartphones) public class SmartphoneController {Autowiredprivate SmartphoneService smartphoneService;RequestMapping(value/create, methodRequestMethod.GET)public ModelAndView createSmartphonePage() {ModelAndView mav new ModelAndView(phones/new-phone);mav.addObject(sPhone, new Smartphone());return mav;}RequestMapping(value/create, methodRequestMethod.POST, produces MediaType.APPLICATION_JSON_VALUE, consumes MediaType.APPLICATION_JSON_VALUE)ResponseBodypublic Smartphone createSmartphone(RequestBody Smartphone smartphone) {return smartphoneService.create(smartphone);}RequestMapping(value/edit/{id}, methodRequestMethod.GET)public ModelAndView editSmartphonePage(PathVariable int id) {ModelAndView mav new ModelAndView(phones/edit-phone);Smartphone smartphone smartphoneService.get(id);mav.addObject(sPhone, smartphone);return mav;}RequestMapping(value/edit/{id}, methodRequestMethod.PUT, produces MediaType.APPLICATION_JSON_VALUE, consumes MediaType.APPLICATION_JSON_VALUE)ResponseBodypublic Smartphone editSmartphone(PathVariable int id, RequestBody Smartphone smartphone) {smartphone.setId(id);return smartphoneService.update(smartphone);}RequestMapping(value/delete/{id}, methodRequestMethod.DELETE, produces MediaType.APPLICATION_JSON_VALUE, consumes MediaType.APPLICATION_JSON_VALUE)ResponseBodypublic Smartphone deleteSmartphone(PathVariable int id) {return smartphoneService.delete(id);}RequestMapping(value, methodRequestMethod.GET,produces MediaType.APPLICATION_JSON_VALUE, consumes MediaType.APPLICATION_JSON_VALUE)ResponseBodypublic List Smartphone allPhones() {return smartphoneService.getAll();}RequestMapping(value, methodRequestMethod.GET)public ModelAndView allPhonesPage() {ModelAndView mav new ModelAndView(phones/all-phones);List Smartphone smartphones new ArrayList Smartphone ();smartphones.addAll(allPhones());mav.addObject(smartphones, smartphones);return mav;}} 您可以将新版本的SmartphoneController与旧版本进行比较。 删除了处理PUTPOSTDELETE请求并返回ModelAndView对象的方法。 由于AJAX调用可以直接寻址到REST方法因此删除了这些方法。 现在控制器仅包含两种类型的方法 第一种将用户定向到可以执行CRUD操作的页面。 第二种类型执行CRUD操作REST方法 客户端 使用AJAX意味着在Web应用程序的客户端上有很多代码。 在本节中我将演示一个基础知识这些基础知识将帮助您了解实现AJAX调用需要执行的步骤。 让我们检查一下在应用程序中创建新智能手机的情况。 首先我需要将JQuery库添加到HTML页面 script src//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js/script HTML的主要部分进行了一次重要的更新-将表单操作属性的扩展名更改为.json div idcontainer h1Create new Smartphone/h1 div pHere you can create new Smartphone:/p div idsPhoneFromResponse/div /div form:form idnewSmartphoneForm action${pageContext.request.contextPath}/smartphones/create.json commandnamesPhone table tbody tr tdProducer:/td td form:select pathproducerform:option valueNOKIANokia/form:optionform:option selectedselected valueIPHONEiPhone/form:optionform:option valueHTCHTC/form:optionform:option valueSAMSUNGSamsung/form:option /form:select /td /tr tr tdModel:/td tdform:input pathmodel/form:input/td /tr tr tdPrice:/td tdform:input pathprice/form:input/td /tr tr tdinput valueCreate typesubmit/td td/td /tr /tbody /table /form:form a href${pageContext.request.contextPath}/index.htmlHome page/a /div 现在女士们先生们我希望介绍一段用于创建新智能手机的JQuery代码 $(document).ready(function() {$(#newSmartphoneForm).submit(function(event) {var producer $(#producer).val();var model $(#model).val();var price $(#price).val();var json { producer : producer, model : model, price: price};$.ajax({url: $(#newSmartphoneForm).attr( action),data: JSON.stringify(json),type: POST,beforeSend: function(xhr) {xhr.setRequestHeader(Accept, application/json);xhr.setRequestHeader(Content-Type, application/json);},success: function(smartphone) {var respContent ;respContent span classsuccessSmartphone was created: [;respContent smartphone.producer : ;respContent smartphone.model : ;respContent smartphone.price ]/span;$(#sPhoneFromResponse).html(respContent); }});event.preventDefault();});}); 我不会停止这段代码并详细解释它因为您可以在官方网站上阅读有关AJAX和JQuery的信息。 简要说明当某人想要提交具有指定ID的表单时所有表单字段都分配给适当的变量。 之后根据表单字段变量生成一个新的JSON文档。 然后执行AJAX调用。 它指向在表单标签的action属性中指定的URL。 JSON用作需要处理的数据。 请求的类型为POST它可以根据操作而有所不同例如对于更新它将具有PUT值。 在beforeSend函数中我明确指定了JSON格式所需的标头。 最后我制定一个响应并将其插入DOM。 就是与智能手机的创作有关的东西。 智能手机的更新与此类似只是请求的类型需要更改。 现在让我们看看如何处理DELETE类型的请求。 和以前一样我需要将URL扩展名更改为.json a href${pageContext.request.contextPath}/smartphones/delete/${sPhone.id}.jsonDelete/a 与POST和PUT相比用于DELETE操作的JQuery代码将有所不同。 $(document).ready(function() {var deleteLink $(a:contains(Delete));$(deleteLink).click(function(event) {$.ajax({url: $(event.target).attr(href),type: DELETE,beforeSend: function(xhr) {xhr.setRequestHeader(Accept, application/json);xhr.setRequestHeader(Content-Type, application/json);},success: function(smartphone) {var respContent ;var rowToDelete $(event.target).closest(tr);rowToDelete.remove();respContent span classsuccessSmartphone was deleted: [;respContent smartphone.producer : ;respContent smartphone.model : ;respContent smartphone.price ]/span;$(#sPhoneFromResponse).html(respContent); }});event.preventDefault();});}); 第一个区别是元素的选择器。 如果使用DELETE我想使用链接但不使用表单。 AJAX调用的类型更改为DELETE值。 没有与请求一起发送的任何数据。 最后我删除了需要删除的智能手机行。 摘要 我希望这份简短的AJAX概述对您有所帮助。 AJAX可以在任何Web应用程序中实现很多功能因此请不要忽略这种与服务器通信的便捷方法。 您可以在GitHub上找到此应用程序。 参考 Spring MVC Fruzenshtein的便笺博客中来自JCG合作伙伴 Alexey Zvolinskiy的AjaxJQuery 。 翻译自: https://www.javacodegeeks.com/2013/09/spring-mvc-ajax-jquery.html
http://www.huolong8.cn/news/226884/

相关文章:

  • 企业如何在网站上做宣传深圳在线制作网站
  • 班级网站设计兰州响应式网站建设
  • 做网站哪个平台好网站空间面板
  • 大连网站哪家做的好?网站可以放多少视频
  • 制作网站river潍坊大型做网站建设的公司
  • 常州专业网站建设公司哪家好网站分页需要前端做还是后端
  • 网站做下cdnwordpress 4.9.6 zh
  • 黄金网站软件app下载安装如何优化网站tkd
  • 海洋做网站国外订房网站怎么和做
  • 网站建设需要的资料小程序做网站
  • 肇庆市住房和城乡建设部网站公司内部网站建设方案
  • 学建站wordpress广东佛山
  • 西安推广网站中国网财经
  • 外国人在中国做美食视频网站进空间的网站
  • 广州哪里有做网站推广wordpress架设服务器
  • 广州白云区建站外贸公司珠海建网站的联系方式
  • 巫山做网站那家好即刻搜索引擎入口
  • php网站开发说明做网站不推广管用吗
  • 建筑工程发布网站单机版网页制作软件
  • 怎样在建立公司网站ps做网站效果图
  • 怎么做可以访问网站成都网站的建设
  • 网站建设公司的市场开发方案个人做网站时不要做什么样的网站
  • 百度一下你就知道官方网站纯html网页模板
  • 男女一起做暖暖网站如何设计网页作业
  • 网站制作算是什么专业苏州网络营销推广软件运营
  • 五分钟自己创建网站的方法商标注册45大类明细
  • 个人网站制作dwnas怎么做网站服务器
  • 网站建设有名的公司广告策划与营销
  • wordpress国外网站网站导航内链建设
  • 乌市正规网站建设wordpress查看图片插件