一步一步實現Spring4 + Hibernate4 + Freemarker2 的註解驅動開發(二.應用配置)
阿新 • • 發佈:2019-02-04
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <context:component-scan base-package="cn.toncen.cms"/> <!-- 以下為SpringMVC內容 --> <!-- 支援spring4.0新的mvc註解 --> <mvc:annotation-driven /> <!-- 啟動Spring MVC的註解功能 測試是否需要下面一行--> <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" /> <!-- 地址對映 --> <bean id="handlerMapping" class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"> </bean> <!-- FreeMarker --> <bean id="viewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver"> <property name="contentType" value="text/html;charset=UTF-8" /> </bean> <bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer"> <!-- 模板根目錄 --> <property name="templateLoaderPath" value="/" /> <!-- 編碼格式 --> <property name="defaultEncoding" value="utf-8" /> <property name="freemarkerSettings"> <props> <prop key="template_update_delay">0</prop> <prop key="default_encoding">UTF-8</prop> <prop key="number_format">0.##########</prop> <prop key="datetime_format">yyyy-MM-dd HH:mm:ss</prop> <prop key="classic_compatible">true</prop> <prop key="template_exception_handler">ignore</prop> </props> </property> </bean>
<!-- 靜態資源快取,避免被filter過濾,找不到資源 -->
<mvc:resourcesmapping="/images/**"location="/WEB-INF/views/images/"
cache-period="31556926"/>
<mvc:resourcesmapping="/js/**"location="/WEB-INF/views/js/"
cache-period="31556926"/>
<mvc:resourcesmapping="/css/**"location="/WEB-INF/views/css/"
cache-period="31556926"/>
</beans>
在MySQL中建立資料庫toncen_cms(本文示例),並建立表site