SSM-网站后台管理系统制作(2)---SSM基本工作原理
SSM基本工作原理
講解網(wǎng)站:https://www.w3cschool.cn/wkspring/dcu91icn.html
構(gòu)建基本工作環(huán)境:
mysql
eclipse(tomcat8.0)
Hbulider(前端頁(yè)面展示)
構(gòu)建Dynamic Web Project,然后寫基本所需的domain,dao,service,到此,基本功能即可實(shí)行,然后加入db.properties鏈接數(shù)據(jù)庫(kù),(applicationContext.xml,springmvc-config.xml,web.xml)就構(gòu)建好了一個(gè)基本的ssm框架了。然后在Controller層里面加入所需要的代碼即可,到此,一個(gè)基本的ssm就可以跑起來(lái)了,當(dāng)然,這是簡(jiǎn)單講解,3個(gè)xml里面還有很多需要學(xué)習(xí)的地方,相關(guān)問(wèn)題見(jiàn)代碼
applicationContext.xml
1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:mybatis="http://mybatis.org/schema/mybatis-spring" 4 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 5 xmlns:p="http://www.springframework.org/schema/p" 6 xmlns:context="http://www.springframework.org/schema/context" 7 xmlns:mvc="http://www.springframework.org/schema/mvc" 8 xmlns:tx="http://www.springframework.org/schema/tx" 9 xsi:schemaLocation="http://www.springframework.org/schema/beans 10 http://www.springframework.org/schema/beans/spring-beans.xsd 11 http://www.springframework.org/schema/context 12 http://www.springframework.org/schema/context/spring-context.xsd 13 http://www.springframework.org/schema/mvc 14 http://www.springframework.org/schema/mvc/spring-mvc.xsd 15 http://www.springframework.org/schema/tx 16 http://www.springframework.org/schema/tx/spring-tx.xsd 17 http://mybatis.org/schema/mybatis-spring 18 http://mybatis.org/schema/mybatis-spring.xsd "> 19 20 <!-- mybatis:scan會(huì)掃描org.fkit.dao包里的所有接口當(dāng)作Spring的bean配置,之后可以進(jìn)行依賴注入--> 21 <mybatis:scan base-package="org.fkit.hrm.dao"/> 22 23 <!-- 掃描org.fkit包下面的java文件,有Spring的相關(guān)注解的類,則把這些類注冊(cè)為Spring的bean --> 24 <context:component-scan base-package="org.fkit.hrm"/> 25 26 <!-- 使用PropertyOverrideConfigurer后處理器加載數(shù)據(jù)源參數(shù) --> 27 <context:property-override location="classpath:db.properties"/> 28 29 <!-- 配置c3p0數(shù)據(jù)源 --> 30 <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"/> 31 32 <!-- 配置SqlSessionFactory,org.mybatis.spring.SqlSessionFactoryBean是Mybatis社區(qū)開(kāi)發(fā)用于整合Spring的bean --> 33 <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean" 34 p:dataSource-ref="dataSource"/> 35 36 <!-- JDBC事務(wù)管理器 --> 37 <bean id="transactionManager" 38 class="org.springframework.jdbc.datasource.DataSourceTransactionManager" 39 p:dataSource-ref="dataSource"/> 40 41 <!-- 啟用支持annotation注解方式事務(wù)管理 --> 42 <tx:annotation-driven transaction-manager="transactionManager"/> 43 44 </beans> View Code
springmvc-config.xml
?
1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xmlns:mvc="http://www.springframework.org/schema/mvc" 5 xmlns:p="http://www.springframework.org/schema/p" 6 xmlns:context="http://www.springframework.org/schema/context" 7 xsi:schemaLocation=" 8 http://www.springframework.org/schema/beans 9 http://www.springframework.org/schema/beans/spring-beans.xsd 10 http://www.springframework.org/schema/mvc 11 http://www.springframework.org/schema/mvc/spring-mvc.xsd 12 http://www.springframework.org/schema/context 13 http://www.springframework.org/schema/context/spring-context.xsd"> 14 15 <!-- 自動(dòng)掃描該包,SpringMVC會(huì)將包下用了@controller注解的類注冊(cè)為Spring的controller --> 16 <context:component-scan base-package="org.fkit.hrm.controller"/> 17 <!-- 設(shè)置默認(rèn)配置方案 --> 18 <mvc:annotation-driven/> 19 <!-- 使用默認(rèn)的Servlet來(lái)響應(yīng)靜態(tài)文件 --> 20 <mvc:default-servlet-handler/> 21 22 <!-- 定義Spring MVC的攔截器 --> 23 <mvc:interceptors> 24 <mvc:interceptor> 25 <!-- 攔截所有請(qǐng)求 --> 26 <mvc:mapping path="/*"/> 27 <!-- 自定義判斷用戶權(quán)限的攔截類 --> 28 <bean class="org.fkit.hrm.interceptor.AuthorizedInterceptor"/> 29 </mvc:interceptor> 30 </mvc:interceptors> 31 32 <!-- 視圖解析器 --> 33 <bean id="viewResolver" 34 class="org.springframework.web.servlet.view.InternalResourceViewResolver" 35 p:prefix="/WEB-INF/jsp/" p:suffix=".jsp"/> 36 37 <!-- 文件上傳下載 --> 38 <bean id="multipartResolver" 39 class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> 40 <!-- 上傳文件大小上限,單位為字節(jié)(10MB) --> 41 <property name="maxUploadSize"> 42 <value>10485760</value> 43 </property> 44 <!-- 請(qǐng)求的編碼格式,必須和jSP的pageEncoding屬性一致,以便正確讀取表單的內(nèi)容,默認(rèn)為ISO-8859-1 --> 45 <property name="defaultEncoding"> 46 <value>UTF-8</value> 47 </property> 48 </bean> 49 50 </beans> View Code?
web.xml?
1 <?xml version="1.0" encoding="UTF-8"?> 2 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"> 3 <!-- 配置spring核心監(jiān)聽(tīng)器,默認(rèn)會(huì)以 /WEB-INF/applicationContext.xml作為配置文件 --> 4 <listener> 5 <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 6 </listener> 7 <!-- contextConfigLocation參數(shù)用來(lái)指定Spring的配置文件 --> 8 <context-param> 9 <param-name>contextConfigLocation</param-name> 10 <param-value>/WEB-INF/applicationContext*.xml</param-value> 11 </context-param> 12 13 <!-- 定義Spring MVC的前端控制器 --> 14 <servlet> 15 <servlet-name>springmvc</servlet-name> 16 <servlet-class> 17 org.springframework.web.servlet.DispatcherServlet 18 </servlet-class> 19 <init-param> 20 <param-name>contextConfigLocation</param-name> 21 <param-value>/WEB-INF/springmvc-config.xml</param-value> 22 </init-param> 23 <load-on-startup>1</load-on-startup> 24 </servlet> 25 26 <!-- 讓Spring MVC的前端控制器攔截所有請(qǐng)求 --> 27 <servlet-mapping> 28 <servlet-name>springmvc</servlet-name> 29 <url-pattern>/</url-pattern> 30 </servlet-mapping> 31 32 <!-- 編碼過(guò)濾器 --> 33 <filter> 34 <filter-name>characterEncodingFilter</filter-name> 35 <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> 36 <init-param> 37 <param-name>encoding</param-name> 38 <param-value>UTF-8</param-value> 39 </init-param> 40 </filter> 41 <filter-mapping> 42 <filter-name>characterEncodingFilter</filter-name> 43 <url-pattern>/*</url-pattern> 44 </filter-mapping> 45 46 <!-- jsp的配置 --> 47 <jsp-config> 48 <jsp-property-group> 49 <!-- 配置攔截所有的jsp頁(yè)面 --> 50 <url-pattern>*.jsp</url-pattern> 51 <!-- 可以使用el表達(dá)式 --> 52 <el-ignored>false</el-ignored> 53 <!-- 不能在頁(yè)面使用java腳本 --> 54 <scripting-invalid>true</scripting-invalid> 55 <!-- 給所有的jsp頁(yè)面導(dǎo)入要依賴的庫(kù),tablib.jsp就是一個(gè)全局的標(biāo)簽庫(kù)文件 --> 56 <include-prelude>/WEB-INF/jsp/taglib.jsp</include-prelude> 57 </jsp-property-group> 58 </jsp-config> 59 60 <error-page> 61 <error-code>404</error-code> 62 <location>/404.html</location> 63 </error-page> 64 65 <welcome-file-list> 66 <welcome-file>index.jsp</welcome-file> 67 </welcome-file-list> 68 </web-app> View Code
?
轉(zhuǎn)載于:https://www.cnblogs.com/meditation5201314/p/10223716.html
總結(jié)
以上是生活随笔為你收集整理的SSM-网站后台管理系统制作(2)---SSM基本工作原理的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: css的垂直居中
- 下一篇: Windows系统IntelliJ ID