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

抚州教育网站建设网站建设需要什么人

抚州教育网站建设,网站建设需要什么人,微分销平台登录,济南市历城区精神文明建设网创建react应用程序1.React式编程简介 React式编程是为具有以下特征的应用程序创造的术语#xff1a; 非阻塞应用 事件驱动和异步 需要少量线程来垂直扩展#xff08;即在JVM中#xff09; 就像面向对象的编程#xff0c;函数式编程或过程式编程一样#xff0c;React式… 创建react应用程序 1.React式编程简介 React式编程是为具有以下特征的应用程序创造的术语 非阻塞应用 事件驱动和异步 需要少量线程来垂直扩展即在JVM中 就像面向对象的编程函数式编程或过程式编程一样React式编程只是另一种编程范例。 它使我们的程序成为响应式弹性弹性。 2. Spring的React式编程 Spring框架在内部使用Reactor为其自身提供响应式支持。 Reactor是Reactive Streams发布程序在Java9中引入的实现。 Reactor具有以下两种数据类型 助焊剂它是一个可以发射0个或多个元素的流 单声道这是一个可以发出0或1个元素的流 Spring从其API公开这些类型从而使应用程序具有响应性。 在Spring5中引入了一个名为WebFlux的新模块该模块支持使用以下命令创建React式Web应用程序HTTPREST和Web套接字。 Spring Web Flux支持以下两种模型 功能模型 注释模型 在本文中我们将探讨功能模型。 下表比较了普通Spring和Web Flux 传统堆栈 React堆 Spring Web MVC SpringWebFlux 控制器和处理程序映射 路由器功能 Servlet API HTTP /React流 Servlet容器 任何支持Servlet 3.1 Tomcat 8.xJettyNettyUnderTow的servlet容器 3.用例 必须为员工管理系统创建一个使用Spring Web Flux的REST API该系统将对CRUD公开。 注意项目的DAO层是硬编码的。 4.所需的软件和环境 Java1.8以上 Maven3.3.9或更高 Eclipse Luna或以上 Sprint Boot2.0.0.M4 Spring Boot Starter WebFlux 邮递员测试应用程序 5.申请流程 Spring5 WebFlux的功能模型是使用Spring MVC样式注释的替代方法。 在Spring WebFlux功能模型中路由器和处理程序函数用于创建MVC应用程序.HTTP请求通过路由器函数路由替代RequestMapping注释请求通过处理函数 替代Controller处理程序方法进行处理。 每个处理程序函数都将ServerRequest org.springframework.web.reactive.function.server.ServerRequest 作为参数结果将返回MonoServerResponse或FluxServerResponse org.springframework.web.reactive.function.server.ServerResponse 。 6.用例代码和描述 pom.xml project xmlnshttp://maven.apache.org/POM/4.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersiongroupIdcom.webflux/groupIdartifactIdDemo_Spring_MVC_Web_Flux/artifactIdversion0.0.1-SNAPSHOT/versionrepositoriesrepositoryidspring-snapshots/idnameSpring Snapshots/nameurlhttps://repo.spring.io/snapshot/urlsnapshotsenabledtrue/enabled/snapshots/repositoryrepositoryidspring-milestones/idnameSpring Milestones/nameurlhttps://repo.spring.io/milestone/urlsnapshotsenabledfalse/enabled/snapshots/repository/repositoriespluginRepositoriespluginRepositoryidspring-snapshots/idnameSpring Snapshots/nameurlhttps://repo.spring.io/snapshot/urlsnapshotsenabledtrue/enabled/snapshots/pluginRepositorypluginRepositoryidspring-milestones/idnameSpring Milestones/nameurlhttps://repo.spring.io/milestone/urlsnapshotsenabledfalse/enabled/snapshots/pluginRepository/pluginRepositoriesparentgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-parent/artifactIdversion2.0.0.M4/versionrelativePath /!-- lookup parent from repository --/parentpropertiesproject.build.sourceEncodingUTF-8/project.build.sourceEncodingproject.reporting.outputEncodingUTF-8/project.reporting.outputEncoding!-- Configuring Java 8 for the Project --java.version1.8/java.version/properties!--Excluding Embedded tomcat to make use of the Netty Server--dependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactIdexclusionsexclusiongroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-tomcat/artifactId/exclusion/exclusions/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-webflux/artifactId/dependency/dependenciesbuildpluginsplugingroupIdorg.springframework.boot/groupIdartifactIdspring-boot-maven-plugin/artifactId/plugin/plugins/build /project EmployeeDAO.java package com.webflux.dao; import java.util.LinkedHashMap; import java.util.Map; import org.springframework.stereotype.Repository; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import com.webflux.bussiness.bean.Employee; Repository public class EmployeeDAO {/*** Map is used to Replace the Database * */static public Map mapOfEmloyeess new LinkedHashMap();static int count10004;static{mapOfEmloyeess.put(10001, new Employee(Jack,10001,12345.6,1001));mapOfEmloyeess.put(10002, new Employee(Justin,10002,12355.6,1002));mapOfEmloyeess.put(10003, new Employee(Eric,10003,12445.6,1003));}/*** Returns all the Existing Employees as Flux* */public Flux getAllEmployee(){return Flux.fromStream(mapOfEmloyeess.values().stream()); }/**Get Employee details using EmployeeId .* Returns a Mono response with Data if Employee is Found* Else returns a null* */public Mono getEmployeeDetailsById(int id){Monores null;Employee emp mapOfEmloyeess.get(id);if(emp!null){resMono.just(emp);}return res;}/**Create Employee details.* Returns a Mono response with auto-generated Id* */public Mono addEmployee(Employee employee){count;employee.setEmployeeId(count);mapOfEmloyeess.put(count, employee);return Mono.just(count);}/**Update the Employee details,* Receives the Employee Object and returns the updated Details* as Mono * */public Mono updateEmployee (Employee employee){mapOfEmloyeess.put(employee.getEmployeeId(), employee);return Mono.just(employee);}/**Delete the Employee details,* Receives the EmployeeID and returns the deleted employee Details* as Mono * */public Mono removeEmployee (int id){Employee emp mapOfEmloyeess.remove(id);return Mono.just(emp);} } 可以观察到 EmployeeDAO所有方法都返回Mono或Flux响应从而使DAO层处于活动状态。 EmployeeHandler.java package com.webflux.web.handler; import static org.springframework.web.reactive.function.BodyInserters.fromObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; import org.springframework.web.reactive.function.BodyExtractors; import org.springframework.web.reactive.function.server.ServerRequest; import org.springframework.web.reactive.function.server.ServerResponse; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import com.webflux.bussiness.bean.Employee; import com.webflux.dao.EmployeeDAO; Controller public class EmployeeHandler {Autowiredprivate EmployeeDAO employeeDAO;/*** Receives a ServerRequest.* Invokes the method getAllEmployee() from EmployeeDAO.* Prepares a Mono and returns the same.* */ public Mono getEmployeeDetails(ServerRequest request) {Flux resemployeeDAO.getAllEmployee(); return ServerResponse.ok().contentType(MediaType.APPLICATION_JSON).body(res,Employee.class);}/*** Receives a ServerRequest.* Extracts the Path Variable (named id) from the Request.* Invokes the method [getEmployeeDetailsById()] from EmployeeDAO.* Verifies if the object returned in the previous step is null * then returns a Bad request with appropriate message.* Else Returns the Mono with the Employee Data.* */public Mono getEmployeeDetailByEmployeeId(ServerRequest request) {//Extracts the Path Variable id from the Requestint id Integer.parseInt(request.pathVariable(id));Mono employee employeeDAO.getEmployeeDetailsById(id);Mono res null;if(employeenull){resServerResponse.badRequest().body(fromObject(Please give a valid employee Id));}else{//Converting Mono of Mono type to Monoresemployee.flatMap(x-ServerResponse.ok().body(fromObject(x))); }return res;}/*** Receives a ServerRequest.* Makes use of BodyExtractors and Extracts the Employee Data as * Mono from the ServerRequest.* Invokes the method [addEmployee()] of the EmployeeDAO.* Prepares a Mono and returns the same. * */public Mono addEmployee(ServerRequest request) {Mono requestBodyMono request.body(BodyExtractors.toMono(Employee.class));Mono mono employeeDAO.addEmployee(requestBodyMono.block());//Converting Mono of Mono type to MonoMono res mono.flatMap(x-ServerResponse.ok().body(fromObject(Employee Created with Idx))); return res;}/*** Receives a ServerRequest.* Makes use of BodyExtractors and Extracts the Employee Data as * Mono from the ServerRequest.* Finds the Employee and updates the details by invoking updateEmployee() of * EmployeeDAO. * Prepares a Mono and returns the same.* */public Mono updateEmployee(ServerRequest request) {Mono requestBodyMono request.body(BodyExtractors.toMono(Employee.class));Employee employee requestBodyMono.block();Mono employeeRet employeeDAO.getEmployeeDetailsById(employee.getEmployeeId());Mono res null;if(employeeRetnull){resServerResponse.badRequest().body(fromObject(Please Give valid employee details to update));}else{Mono emp employeeDAO.updateEmployee(employee);//Converting Mono of Mono type to Monoresemp.flatMap(x-ServerResponse.ok().body(fromObject(x)));}return res; }/*** Receives a ServerRequest.* Makes use of BodyExtractors and Extracts the Employee Data as * Mono from the ServerRequest.* Finds the Employee and deletes the details by invoking removeEmployee() of * EmployeeDAO. * Prepares a Mono and returns the same.* */public Mono deleteEmployee(ServerRequest request) {int myId Integer.parseInt(request.pathVariable(id));Mono res null;if (employeeDAO.getEmployeeDetailsById(myId) null) {resServerResponse.badRequest().body(fromObject(Please Give valid employee details to delete));}else{Mono employee employeeDAO.removeEmployee(myId);//Converting Mono of Mono type to Monoresemployee.flatMap(x-ServerResponse.ok().body(fromObject(x))); }return res;} } 可以看出Handler的所有方法都返回MonoServerResponse 从而使表示层处于响应状态。 注意 事件处理程序方法应接受ServerRequest并返回MonoServerResponse RouterConfiguration.java package com.webflux.web.router.config; import static org.springframework.web.reactive.function.server.RequestPredicates.DELETE; import static org.springframework.web.reactive.function.server.RequestPredicates.GET; import static org.springframework.web.reactive.function.server.RequestPredicates.POST; import static org.springframework.web.reactive.function.server.RequestPredicates.PUT; import static org.springframework.web.reactive.function.server.RequestPredicates.accept; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.MediaType; import org.springframework.web.reactive.function.server.RouterFunction; import org.springframework.web.reactive.function.server.RouterFunctions; import org.springframework.web.reactive.function.server.ServerResponse; import com.webflux.web.handler.EmployeeHandler; Configuration /*** Router is configuration class.* It links the incoming requests with appropriate HTTP methods to the * respective method of the EmployeeHandler.* Method references are used for the mapping.* */ public class RouterConfiguration{AutowiredEmployeeHandler employeeHandler;Beanpublic RouterFunction monoRouterFunction() {RouterFunctionrouterFunction RouterFunctions. route(GET(/emp/controller/getDetails).and(accept(MediaType.APPLICATION_JSON)), employeeHandler::getEmployeeDetails).andRoute(GET(/emp/controller/getDetailsById/{id}).and(accept(MediaType.APPLICATION_JSON)), employeeHandler::getEmployeeDetailByEmployeeId).andRoute(POST(/emp/controller/addEmp).and(accept(MediaType.APPLICATION_JSON)), employeeHandler::addEmployee).andRoute(PUT(/emp/controller/updateEmp).and(accept(MediaType.APPLICATION_JSON)), employeeHandler::updateEmployee).andRoute(DELETE(/emp/controller/deleteEmp/{id}).and(accept(MediaType.APPLICATION_JSON)), employeeHandler::deleteEmployee);return routerFunction;} } ApplicationBootUp.java package com.webflux; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; SpringBootApplication public class ApplicationBootUp {public static void main(String[] args) {SpringApplication.run(ApplicationBootUp.class);}} 在application.properties内部仅提及服务器端口 server.port8090 。 可以使用以下命令部署应用程序 clean install spring-boot:run并使用postman client进行测试。 7.参考 https://docs.spring.io/spring/docs/5.0.0.BUILD-SNAPSHOT/spring-framework-reference/html/web-reactive.html http://www.baeldung.com/reactor-core http://www.baeldung.com/spring-5-functional-web 8.下载Eclipse项目 下载 您可以在此处下载此示例的完整源代码 SpringWebFlux 翻译自: https://www.javacodegeeks.com/2018/01/reactive-web-applications-using-springwebflux.html创建react应用程序
http://www.pierceye.com/news/891641/

相关文章:

  • 彩票网站做一级代理犯法吗购物网站开发设计类图
  • 固镇做网站多少钱乐清网络公司哪家好
  • 绿色农业网站模板做网站有什么比较好看的动效
  • 百度aipage智能建站系统wordpress打印代码
  • 深圳招聘官网深圳搜索引擎优化推广便宜
  • 创建网站大约9377传奇
  • 单页面网站可以做自适应网站吗建筑设计培训
  • 做海报可以在哪些网站下载素材一键生成装修效果图app
  • 福田区住房和建设局官方网站wordpress仿凡客商城主题
  • 做下载网站用什么程序好深圳公司注册服务
  • 猎头网站模板济源专业网站建设(制作网站)
  • kotlin做网站单页应用网站
  • 邢台网站改版开发长沙教育网站开发
  • 网站开发人员必备技能网站背景图片自动切换
  • 企业网站建立策划书有网站吗给一个
  • 外贸建站有哪些公司建设主管部门网站查询
  • 泰安市网站建设广州优化公司哪家好
  • 手机网游传奇西安关键词优化平台
  • 网站建设公司权威机构3d虚拟人物制作软件
  • 北京网站建设seo公司哪家好阿里巴巴企业邮箱登录入口
  • 广州shopify代建站新产品代理
  • html5网站特点在线搜索引擎
  • 网站搭建服务平台网站备案 关闭网站
  • 高端建站收费标准宣传设计网站
  • 视频网站数据库设计手机企业网站设计
  • 广安发展建设集团有限公司门户网站竞价推广代运营服务
  • 济南mip网站建设公司山西住房建设厅网站
  • 兰州需要做网站的公司有哪些做词云的网站
  • 红酒公司网站建设模板6841如何通过网站获取qq
  • 写一张营销型网站页面多长时间微动漫怎么制作