日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

搭建基于spring MVC框架 + RESTful架构风格技术总结

發(fā)布時間:2023/12/31 c/c++ 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 搭建基于spring MVC框架 + RESTful架构风格技术总结 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

2019獨角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>

實戰(zhàn)篇: 在SpringMVC框架中搭建RESTful架構(gòu)風(fēng)格來完成客戶端與服務(wù)器端的低耦合度、可擴展性、高并發(fā)與大數(shù)據(jù)流量的訪問。 用RESTful架構(gòu)的創(chuàng)建步驟: 1.創(chuàng)建一個全新的Web工程 2.導(dǎo)包,導(dǎo)入所需要的所有第三方j(luò)ar包。(springMVC+Hibernate的基本包是必須的) 3.作配置,針對不同的項目需求和不同的搭建設(shè)計,開發(fā)人員可以按照自己的編碼風(fēng)格來設(shè)計符合項目開發(fā)具體 應(yīng)該用多少篇配置文件。但是這幾篇配置文件是必不可少的: 3-1.web.xml配置文件:最基本的配置如下: <?xml?version="1.0"?encoding="UTF-8"?> <web-app?xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee?http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID"?version="2.5"> <display-name>epetrestful</display-name> <servlet> <servlet-name>springMVCReSTful</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:config/spring/spring-action.xml</param-value> </init-param> <load-on-startup>1</load-on-startup>???? </servlet> <servlet-mapping> <servlet-name>springMVCReSTful</servlet-name> <url-pattern>/</url-pattern><!--?直接通過/去匹配路徑?--> </servlet-mapping> <!--?如果有亂碼我們則需要配置字符編碼集的過濾器來防止亂碼問題?--> <filter> <filter-name>encodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>utf-8</param-value> </init-param> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>???? <welcome-file-list> <welcome-file>index.jsp</welcome-file> <welcome-file>login.html</welcome-file> </welcome-file-list> </web-app> 注: 3-2.配置spring-commoms.xml文件。(要注意我們需要將連接數(shù)據(jù)庫資源的信息用一篇外部的database.prpertise的屬性文件來 具體的配置到該spring-commoms.xml的配置文件中)最基本的配置如下: <?xml?version="1.0"?encoding="UTF-8"?> <beans?xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"?xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop"?xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd" default-autowire="byName"> <!--?告知外部的database.propertise文件到spring容器中?--> <bean?class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property?name="location"></property><!--這里name屬性的值必須是location,它是在? PropertyPlaceholderConfigurer類中調(diào)用了這個location的屬性--> <list> <value>classpath:database.prppertise</value><!--?綁定外部寫的database.prppertise屬性文件的路徑?--> </list> </bean> <!--?配置數(shù)據(jù)源的驅(qū)動連接,這樣配置的優(yōu)勢在于:效率得到了提高,具有pool池,我們在進(jìn)行增刪 改查時就不用每次都要連接數(shù)據(jù)庫這樣的一個操作。?--> <bean?id="dataSoure"?class="org.apache.commons.dbcp.BasicDataSource"?> <property?name="driverClassName"> <value>${driverClassName}</value> </property> <property?name="url"> <value>${url}</value> </property> <property?name="username"> <value>${username}</value> </property> <property?name="password"> <value>${password}</value> </property>??? </bean> <!--?告知Hibernate的sessionFactory?-->???? <bean?id="sessionFactory"? class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> <property?name="dataSource"?ref="dataSoure"></property>?????? <property?name="hibernateProperties"></property> <props?key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</props>? <props?key="hibernate.show_sql">true</props> <props?key="hibernate.format_sql">true</props> <property?name="packagesToScan"> <list> <value>com.lh.model</value> </list> </property> </bean> <!--?事物管理器的配置?--> <bean?id="transactionManager"? class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <property?name="sessionFactory"?ref="sessionFactory"></property>??? </bean> <!--?掃描Spring注解的配置?--> <context:component-scan?base-package="com.lh"></context:component-scan> <!--?添加注解事物支持的配置?-->???? <tx:annotation-driven?transaction-manager="transationManager"></tx:annotation-driven> </beans> 3-3.配置一篇spring-action.xml文件(其中在該配置文件中需要將上面的spring-commoms.xml的配置 文件導(dǎo)入到其間,這里體現(xiàn)了在輕量級的spring容器中spring?MVC框架是包含在spring容器之中的。) 基本配置如下: <?xml?version="1.0"?encoding="UTF-8"?> <beans?xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd" default-autowire="byName" > <!--導(dǎo)入外部的spring-commons.xml的配置文件?-->??????? <import?resource="classpath:config/spring/spring-commons.xml"/> <!--配置spring?MVC的注解?驅(qū)動?--> <mvc:annotation-driven/> <!--配置靜態(tài)文件??-->?????? <mvc:default-servlet-handler/> </beans> 故,綜上所述:在一個用spring?MVC框架來實現(xiàn)RESTful架構(gòu)風(fēng)格的互聯(lián)網(wǎng)終端接口至少都需要3篇 或3篇以上的配置文件(關(guān)鍵看程序員自己的風(fēng)格來決定)。 4.設(shè)計頁面(可用html,jsp) 5.書寫model類(表現(xiàn)層),因為后端的開發(fā)用到了Hibernate框架的(ORM映射)對象關(guān)系映射技術(shù),故,model的對象屬性要與數(shù)據(jù)庫表的字段 相對應(yīng),于此,才能達(dá)到關(guān)系數(shù)據(jù)庫和面向?qū)ο笾g的映射(即采用hibernate的注解形式將關(guān)系和對象進(jìn)行綁定)。 6.書寫dao(數(shù)據(jù)訪問層)和daoImpl(接口實現(xiàn)類)。 7.書寫service(業(yè)務(wù)層)和serviceImpl(接口實現(xiàn)類)。 8.書寫單元測試,進(jìn)行校驗功能是否滿足要求。 9.重要環(huán)節(jié):導(dǎo)入我們在開發(fā)過程中所需要使用的所有js,css,jQuery,在一個Web項目中他們都應(yīng)該放入WebRoot的同級目錄下。

轉(zhuǎn)載于:https://my.oschina.net/lwhmdj0823/blog/530638

總結(jié)

以上是生活随笔為你收集整理的搭建基于spring MVC框架 + RESTful架构风格技术总结的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。