SSM基础配置文件

工程目录结构(db.properties,spring.xml直接放在src下,web.xml直接放在web-inf下):

以MySQL为例(SqlServer和Oracle类似,只需要把spring.xml的数据源改了就行):

db.properties:

 #MySQL
MySQL_Driver=com.mysql.jdbc.Driver
MySQL_Url=jdbc:mysql://192.168.1.1:3307/zxy
MySQL_User=root
MySQL_Pwd=root

#SqlServer
SqlServer_Driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
SqlServer_Url=jdbc:sqlserver://192.168.1.1:1433;databaseName=zxy
SqlServer_User=sa
SqlServer_Pwd=sa

#ORACLE

Oracle_Driver = oracle.jdbc.driver.OracleDriver

Oracle_Url = jdbc\:oracle\:thin\:@192.168.1.1\:1521\:zxy

Oracle_User = system

Oracle_Pwd = system


spring.xml:

<!-- 加载属性资源文件 -->
<util:properties id="db" location="classpath:db.properties"/>

<!-- 定义数据源 -->
<bean id="ds" destroy-method="close"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="#{db.MySQL_Driver}"/>
<property name="url" value="#{db.MySQL_Url}"/>
<property name="username" value="#{db.MySQL_User}"/>
<property name="password" value="#{db.MySQL_Pwd}"/>
</bean>

<!-- 配置SqlSessionFactoryBean -->
<bean class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="ds"/>
<property name="mapperLocations"
value="classpath:com/c...n/fcwt/mapper/*.xml"/> <!-- 要改 -->
</bean>

<!-- 配置MapperScannerConfigurer扫描对象 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.c...n.fcwt.dao"/> <!-- 要改 -->
<property name="annotationClass"
value="com.c...n.fcwt.annotation.MyAnnotation"/> <!-- 要改 -->
</bean>

<!-- 开启注解扫描 -->
<context:component-scan base-package="com.c...n.fcwt"/> <!-- 要改 -->

<!-- 开启MVC注解扫描 -->
<mvc:annotation-driven/>

<!-- 定义视图解析器ViewResolver -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/"/>
<property name="suffix" value=".jsp"/>
</bean>


web.xml:

<!-- springMVC前端控制器 -->
<servlet>
<servlet-name>springMVC</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring.xml</param-value>
</init-param>

<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>springMVC</servlet-name>
<url-pattern>*.do</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>
</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-list>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值