使用Spring 简化MyBatis
1、导入mybatis所有的jar 和 spring 基本包,spring-jdbc,spring-tx,spring-aop,spring整合mybatis的包等。
2、编写spring配置文件applicationCotext.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- 数据源封装类,数据源 获取数据连接 spring.jdbc.jar中-->
<bean id="dataSouce" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://localhost:3306/ssm"></property>
<property name="username" value="root"></property>
<property name="password" value="362222"></property>
</bean>
<!-- 创建SqlSessionFactory对象 -->
<bean id="factory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 数据库连接对象信息来源于dataSouce(上面) -->
<property name="dataSource" ref="dataSouce"></property>
</bean>
<!-- 扫描器相当于mybatis.xml中的mappers下的package标签 ,扫描com.bjsxt.mapper包后会给对应的接口创建对象-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- 要扫描那个包 -->
<property name="basePackage" value="com.bjsxt.mapper"></property>
<!-- 和factory产生关系 -->
<property name="sqlSessionFactory" ref="factory"></property>
</bean>
<!-- 由spring管理service实现类 -->
<bean id="airportservice" class="com.bjsxt.service.impl.AirportServiceImpl">
<property name="airportMapper" ref="airportMapper"></property>
</bean>
</beans>
3、编写代码
3.1 正常编写pojo
3.2 编写mapper包下时必须使用接口绑定方案或注解方案(必须有接口)
3.3 正常编写Service接口和Service实现类
3.3.1 需要在Service实现类中声明Mapper接口对象,并生成get/set方法
3.4 spring无法管理Servlet
使用Spring 简化MyBatis的更多相关文章
- Spring和MyBatis环境整合
SSH框架的结合几乎家喻户晓,但是一般的中小项目,使用Spring和MyBatis就够了,而且MyBatis轻便好使,易上手,值得大家尝试一次. 开篇简介: Spring: Spring是一个轻量级的 ...
- Spring与Mybatis配置问题
Spring和Mybatis的整合,主要借助于Spring的依赖注入和控制反转来简化Mybatis的配置,使用两个配置文件[注:此种配置文件网上已经有很多]: spring.xml: <?xml ...
- Spring+SpringMVC+MyBatis深入学习及搭建(二)——MyBatis原始Dao开发和mapper代理开发
转载请注明出处:http://www.cnblogs.com/Joanna-Yan/p/6869133.html 前面有写到Spring+SpringMVC+MyBatis深入学习及搭建(一)——My ...
- Spring+SpringMVC+MyBatis+easyUI整合
进阶篇 Spring+SpringMVC+MyBatis+easyUI整合进阶篇(一)设计一套好的RESTful API 优化篇 Spring+SpringMVC+MyBatis+easyUI整合优化 ...
- Spring+SpringMVC+MyBatis+easyUI整合进阶篇(二)RESTful API实战笔记(接口设计及Java后端实现)
写在前面的话 原计划这部分代码的更新也是上传到ssm-demo仓库中,因为如下原因并没有这么做: 有些使用了该项目的朋友建议重新创建一个仓库,因为原来仓库中的项目太多,结构多少有些乱糟糟的. 而且这次 ...
- Spring+SpringMVC+MyBatis+easyUI整合基础篇
基础篇 Spring+SpringMVC+MyBatis+easyUI整合基础篇(一)项目简介 Spring+SpringMVC+MyBatis+easyUI整合基础篇(二)牛刀小试 Spring+S ...
- SSM(Spring + Springmvc + Mybatis)框架面试题
JAVA SSM框架基础面试题https://blog.csdn.net/qq_39031310/article/details/83050192 SSM(Spring + Springmvc + M ...
- 用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建四:配置springmvc
在用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建三:配置spring并测试的基础上 继续进行springmvc的配置 一:配置完善web.xml文件
- Spring Boot + Mybatis + Redis二级缓存开发指南
Spring Boot + Mybatis + Redis二级缓存开发指南 背景 Spring-Boot因其提供了各种开箱即用的插件,使得它成为了当今最为主流的Java Web开发框架之一.Mybat ...
随机推荐
- php中bootstrap框架.popover弹出框,鼠标移动到上面自动显示,离开自动消失
<div rel="name"></div> <script> $(function(){//显示弹出框 $("[rel=name]& ...
- http://www.bugku.com:Bugku——变量1(http://120.24.86.145:8004/index1.php)
之前立志做出需要编码解决和时间相关的那道CTF题目,但是这次没找到,相关人士找到了麻烦告诉我一声.本次再学习一下子关于正则表达式和PHP的相关知识.开课咯-.- 刚看题目就发现提示, ...
- Sigma Function (平方数与平方数*2的约数和是奇数)
Sigma Function https://vjudge.net/contest/288520#problem/D Sigma function is an interesting function ...
- C#后台对密码框不能直接赋值
当页面密码框 为 textmode="textpassword"时候,使用 txtpwd.text="XXX",是不会显示的, 应该使用txtpass.Attr ...
- android轮播图的实现原理
1.轮播图的点:RadioGroup,根据网络请求的数据,解析得到的图片的个数,设置RadioGroup的RadioButton的个数. 2.轮播图的核心技术:用Gallery来存放图片,设置适配器. ...
- 访问注解(annotation)的几种常见方法
java的注解处理器类主要是AnnotatedElement接口的实现类实现,为位于java.lang.reflect包下.由下面的class源码可知AnnotatedElement接口是所有元素的父 ...
- HTML转义字符 Unicode和CSS伪类介绍
CSS 伪类用于向某些选择器添加特殊的效果. a:link {color: #FF0000} /* 未访问的链接 */ a:visited {color: #00FF00} /* 已访问的链接 */ ...
- jquery ajax 中实现给变量赋值
我们在用JQuery的Ajax从后台提取数据后想把它赋值给全局变量,但是却怎么都赋不进,为什么呢? 原因其实很简单,我们用的Ajax是异步操作,也就是说在你赋值的时候数据还没提取出来,你当然赋不进去, ...
- u-boot之内核是怎么启动的
在u-boot之start_armboot函数分析已经分析过了整个程序框架,但只是说了下什么时候运行内核,并没有具体说明是怎么执行内核的.内核启动分以下几个步骤说明: 1.启动参数bootcmd=na ...
- web 框架本质 及python三大框架对比
. 导入Bootstrap.css (开发版3.3.7) . 还要Bootstrap.js,并且还要引入jQuery(). . 栅格系统 . container,row必须包含在container中 ...