SSM整合eclipse篇

配置tomcat
此项目为jar包导入,无需配置maven.
自行参考:配置tomcat
新建项目
在这里插入图片描述
选择版本—》新建
在这里插入图片描述
在这里插入图片描述
导入对应jar包(复制粘贴进lib文件夹就好啦)
在这里插入图xi片描述
开始整合
新建applicationContext.xml此文件主要用于整合spring+mybatis

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

	
	
	<!-- 加载db.properties文件 -->
	<bean  id="config" class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">
		<property name="locations">
			<array>
				<value>classpath:db.properties</value>
			</array>
		</property>
		
	</bean>
	<!-- 配置配置数据库信息(替代mybatis的配置文件conf.xml) -->
	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
			<property name="driverClassName" value="${driver}"></property>
			<property name="url" value="${url}"></property>
			<property name="username" value="${username}"></property>
			<property name="password" value="${password}"></property>
	</bean>
	
	
	<!-- conf.xml :  数据源,mapper.xml -->
	<!-- 配置MyBatis需要的核心类:SqlSessionFactory -->
	<!-- 在SpringIoc容器中 创建MyBatis的核心类 SqlSesionFactory -->
	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource"></property>
		<!-- 加载mapper.xml路径 -->
		<property name="mapperLocations" value="classpath:com/kuang/mapper/*.xml"></property>
		</bean>
		
	
	<!-- 将MyBatis的SqlSessionFactory 交给Spring -->
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
	 	<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
	 	<property name="basePackage" value="com.kuang.mapper"></property>
	 	<!--上面basePackage所在的property的作用:
	 	将org.lanqiao.mapper包中,所有的接口   产生与之对应的 动态代理对象
	 	(对象名 就是 首字母小写的接口名) :studentMapper.querystudentBYNO();
	 	  -->
	 </bean>
	 

</beans>

新建applicationContext-controller.xml此文件主要用于整合spring+springmvc

<?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:mvc="http://www.springframework.org/schema/mvc"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">
	<!-- 将控制器所在包 加入IOC容器 -->
	<context:component-scan base-package="com.kuang"></context:component-scan>
		
		
	<!-- 配置视图解析器 -->
	<bean  class="org.springframework.web.servlet.view.InternalResourceViewResolver">
			<property name="prefix" value="/views/"></property>
			<property name="suffix" value=".jsp"></property>
	</bean>
	
	<!-- SPringMVC基础配置、标配 -->
	<mvc:annotation-driven></mvc:annotation-driven>

</beans>

新建db.properties此文件主要配置数据库相关信息(根据自己的数据库进行相应配置)

driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/stuu?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false
username=root
password=1475369a


配置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>yqssm</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  
  
  <!-- Web项目中,引入Spring -->
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:applicationContext.xml</param-value>
	</context-param>

	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	
	
	<!-- 整合SPringMVC -->
	<servlet>
		<servlet-name>springDispatcherServlet</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>classpath:applicationContext-controller.xml</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>

	<!-- Map all requests to the DispatcherServlet for handling -->
	<servlet-mapping>
		<servlet-name>springDispatcherServlet</servlet-name>
		<url-pattern>/</url-pattern>
	</servlet-mapping>
  
	
     <!-- 配置字符编码过滤器 -->
    <filter>
        <filter-name>encoding</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>encoding</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
  
</web-app>

lib包分享地址:
链接:https://pan.baidu.com/s/1FHiTFb-DkJus2emS7G8MnQ
提取码:0314

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值