springMVC+MyBatis+Oracle+Web实现增删改查(附带完整案例+数据库数据)

在网上也是搜索很多资料一点点学到现在。东西整合在一起,希望对各位有所帮助一、准备工作:1.先看下目录结构2.需要的jar包二、配置文件解读配置文件有这么几个    web.xml,springMvc的配置文件(spring-mvc.xml,daoContext.xml),数据库属性文件mysql.properties,MyBatis的配置文件MyBatis-co
摘要由CSDN通过智能技术生成

在网上也是搜索很多资料一点点学到现在。东西整合在一起,希望对各位有所帮助

一、准备工作:

1.先看下目录结构



2.需要的jar包



二、配置文件解读

配置文件有这么几个    web.xml,springMvc的配置文件(spring-mvc.xml,daoContext.xml),数据库属性文件mysql.properties,MyBatis的配置文件MyBatis-config.xml,MyBatis与数据库映射文件userMapper.xml。下面逐一讲解

1.web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 
	xmlns="http://java.sun.com/xml/ns/javaee" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
	http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<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>
	     <init-param>
	         <param-name>forceEncoding</param-name>
	         <param-value>true</param-value>
	     </init-param>
 </filter>
 
 <filter-mapping>
        <filter-name>characterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
 </filter-mapping>
 
  <welcome-file-list>
      <welcome-file>/WEB-INF/index.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
		<init-param>
		    <description>加载spring-mvc文件夹下xml的配置文件</description>
			<param-name>contextConfigLocation</param-name>
			<param-value>/WEB-INF/spring-mvc/*.xml</param-value>
		</init-param>
	  <load-on-startup>1</load-on-startup>
      <servlet-name>test</servlet-name>
      <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  </servlet>
  <servlet-mapping>
      <servlet-name>test</servlet-name>
      <url-pattern>/</url-pattern>
  </servlet-mapping>
</web-app>
<filter>是为了防止乱码加的

<servlet>中<init-param>是在加载文件夹spring-mvc文件夹下关于springMvc 配置的xml的配置文件
另外需要注意的是:servlet-name是随意的。但是如果没有<init-param>中加载xml这句话时,spring会自动找到test-servlet.xml文件。这时就需要spring配置文件名与其一致,否则会报错

2.spring-mvc有两个配置文件:spring-mvc.xml和daoContext.xml

(1)spring-mvc.xml 顾名思义是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:tx="http://www.springframework.org/schema/tx"
	xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="
  http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
  http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
  http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
  http://www.springframework.org/schema/mvc  http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
    <!-- 启用 spring mvc 注解 -->
    <mvc:annotation-driven/>
	<!-- 对com.yue下所有包下的类的注解进行扫描,并自动创建bean实例和装配bean -->
	<context:component-scan base-package="com.yue"></context:component-scan>
	
    <!-- 视图解析器,定义跳转的文件前后缀 -->
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
         <property name="prefix" value="/WEB-INF/jsp/"/>
         <property name="suffix" value=".jsp"/>
    </bean>
</beans>

<pre name="code" class="html">启用注解:当url中有deleteUser.do,则去文件中找@RequestMapping(value="deleteUser.do")这句话,并对应执行他的方法
视图解析器:java方法中return "main";则会去找“/WEB-INF/jsp/main.jsp”的文件。对应起来就是一个完整的请求返回过程
 
<pre name="code" class="html">(2)daoContext.xml中是一些与数据库相关的连接配置文件</p><p></p><pre name="code" class="html">

 
<?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:tx="http://www.springframework.org/schema/tx"
	xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="
  http://www.springframe
  • 5
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值