Eclipse搭建Sprng+SpringMVC+Mybatis框架

Eclipse搭建Sprng+SpringMVC+Mybatis框架

这个给项目整体也是我看视频学的,由于我之前自己找项目十分难找所有分享上来
所需jar包
链接:https://pan.baidu.com/s/1Uu8reoP0AXFTL__gXmsAog
提取码:4ma5
整体项目目录

在这里插入图片描述

第一步

打开eclipse,单击右键–》new–》Dynamic Web Project,输入项目名称后一直点击next到最后一步,勾选创建web.xml后点击finish,主要的目录为图中选中的三部分
在这里插入图片描述

第二步

复制spring、springmvc和mybatis的jar包加入到lib目录中,选中所有jar包右键BuildPath->add Build Path

在这里插入图片描述

第三步

在web.xml中添加spring的监听器,springmvc的前端控制器

<?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_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>teaching_ssm</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>
  <filter>
    <filter-name>characterEncodingFilter</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>characterEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <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>
  <servlet>
    <servlet-name>dispatcherServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:springmvc.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>dispatcherServlet</servlet-name>
    <url-pattern>*.shtml</url-pattern>
  </servlet-mapping>
</web-app>

applicationContext.xml

<?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:p="http://www.springframework.org/schema/p"
	xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="
       http://www.springframework.org/schema/beans 
       http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-3.2.xsd
       http://www.springframework.org/schema/tx
       http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
       
       
       <bean id="propertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
       		
       		<property name="location" value="classpath:jdbc.properties"></property>
       </bean>
       
       
       <bean id="basicDataSource" 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>
       
       
       <bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
       	
       	<property name="configLocation" value="classpath:mybatis.xml"/>
       	<property name="dataSource" ref="basicDataSource"></property>
       
       	<property name="mapperLocations" value="classpath*:cn/java/mapper/*.xml"></property>
       </bean>
       
      
       <bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
       	<property name="basePackage" value="cn.java.mapper"></property>
       </bean>
 
</beans>

springmvc.xml

<?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:p="http://www.springframework.org/schema/p"
	xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="
       http://www.springframework.org/schema/beans 
       http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-3.2.xsd
       http://www.springframework.org/schema/tx
       http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
       
    
       <bean id="propertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
       		
       		<property name="location" value="classpath:jdbc.properties"></property>
       </bean>
       
      
       <bean id="basicDataSource" 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>
       
       <
       <bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
     
       	<property name="dataSource" ref="basicDataSource"></property>
  
       	<property name="mapperLocations" value="classpath*:cn/java/mapper/*.xml"></property>
       </bean>
       
       <bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
       	<property name="basePackage" value="cn.java.mapper"></property>
       </bean>
 
</beans>

jdbc.properties

#mysql
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://teaching_ssm?characterEncoding=utf-8
username=root
password=root

mybatis.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>

	<!-- 别名 -->
	<typeAliases>
		<package name="cn.java.entity"/>
	</typeAliases>

</configuration>

项目搭建完成 新项目能够启动就基本没有什么问题了
如果要做软件项目或咨询框架问题可以加微信
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值