`
mywebcode
  • 浏览: 998842 次
文章分类
社区版块
存档分类
最新评论

springmvc\freemarcker\ibatis配置文件

 
阅读更多


<?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:aop="http://www.springframework.org/schema/aop"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:p="http://www.springframework.org/schema/p"
	xmlns:mvc="http://www.springframework.org/schema/mvc" 
	xsi:schemaLocation=
	"http://www.springframework.org/schema/beans 
	http://www.springframework.org/schema/beans/spring-beans-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/context 
	http://www.springframework.org/schema/context/spring-context-3.0.xsd
	http://www.springframework.org/schema/tx 
    http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    http://www.springframework.org/schema/p 
	http://www.springframework.org/schema/p/spring-p-3.0.xsd
	http://www.springframework.org/schema/mvc 
	http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

     <!-- 自动扫描bean,把作了注解的类转换为bean -->  
     <context:component-scan base-package="com,com.xuan" />
     
     <mvc:annotation-driven />
     <!-- 取消对resources这个文件夹的拦截,可以访问静态文件的文件夹 -->
     <mvc:resources location="/resources/" mapping="/resources/**"/>
     <mvc:default-servlet-handler/>
      
     
 <!-- 数据库配置 -->
   <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
		<property name="url" value="jdbc:mysql://localhost:3306/refectory"></property>
		<property name="username" value="root"></property>
		<property name="password" value="123456"></property>
		<property name="initialSize" value="5"></property>
		<property name="maxActive" value="100"></property>
		<property name="maxIdle" value="10"></property>
   </bean>
   

	<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
		<property name="configLocation">
			<value>classpath:SqlMapConfig.xml</value>
		</property>
		<property name="dataSource">
			<ref local="dataSource"/>
		</property>
	</bean>
	
   <bean id="sqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate">
      <property name="sqlMapClient" ref="sqlMapClient" />
   </bean>
	
	<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource" />
	</bean>
	
	
	<tx:advice id="txAdvice" transaction-manager="transactionManager">
		<tx:attributes>
			<tx:method name="trans*" propagation="REQUIRED" />
		</tx:attributes>
	</tx:advice>
	


<!-- freemarker的配置 -->
 <bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
   <property name="templateLoaderPath" value="/WEB-INF/views/" />
   <property name="defaultEncoding" value="UTF-8" />
   <property name="freemarkerSettings">
   <props>
    <prop key="template_update_delay">10</prop>
    <prop key="locale">zh_CN</prop>
    <prop key="datetime_format">yyyy-MM-dd</prop>
    <prop key="date_format">yyyy-MM-dd</prop>
    <prop key="number_format">#.##</prop>
   </props>
  </property>
  
 </bean>
 

<!-- FreeMarker视图解析   如返回student。。在这里配置后缀名ftl和视图解析器。。-->
 <bean id="viewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
	  <property name="viewClass" value="org.springframework.web.servlet.view.freemarker.FreeMarkerView"></property>
	  <property name="suffix" value=".ftl" />
	  <property name="contentType" value="text/html;charset=utf-8" />
	  <property name="exposeRequestAttributes" value="true" />
	  <property name="exposeSessionAttributes" value="true" />
	  <property name="exposeSpringMacroHelpers" value="true" />
	  <!-- 前段可以通过${request.getContextPath}获取根路径 -->
	  <property name="requestContextAttribute" value="request"></property>

 </bean>  

 

 
 <!-- 文件上传 -->
      <bean id="multipartResolver" 
           class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
         <!-- 设置上传文件大小的参数 -->
        <property name="maxUploadSize" value="1000000"/>
       </bean>

 
</beans>

ibatis总配置文件:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMapConfig
   PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
    "http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
    <settings enhancementEnabled="true" useStatementNamespaces="true"/>
    
    <sqlMap resource="com/sqlmap/user.xml"></sqlMap>
</sqlMapConfig>

映射文件配置:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap
	PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"
	"http://ibatis.apache.org/dtd/sql-map-2.dtd">

<sqlMap namespace="users">
   <typeAlias type="com.restaurant.model.UserModel" alias="user"/>
   
   
	<select id="getUserById"  parameterClass="java.lang.String" resultClass="user">
	   select * from user where user_id=#userid#
	</select>
	
</sqlMap>
	


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics