通过注解整合

1.在UserDao同级目录下新建接口UserMapper,内容如下:

public interface UserMapper {
@Select("select * from user")
public List<User> selectUser();
}

2.新建service包,改写UserDao和其实现类为UserService类和其实现类,如下:

public interface UserService {
public List<User> selectUser();
} public class UserServiceImp implements UserService {
private UserMapper userMapper;
@Override
public List<User> selectUser() {
return userMapper.selectUser();
} public void setUserMapper(UserMapper userMapper) {
this.userMapper = userMapper;
}
}

3.beans.xml新增bean标签、修改原UserDao标签,如下:

<bean id="userMapper" class="org.mybatis.spring.mapper.MapperFactoryBean">
<property name="mapperInterface" value="com.lxy.dao.UserMapper"/>
<property name="sqlSessionFactory" ref="sqlSessionFactory"></property>
</bean>
<bean id="userService" class="com.lxy.service.imp.UserServiceImp">
<property name="userMapper" ref="userMapper"/>
</bean>

4.修改test为新的类型,如下:

public class test {
public static void main(String[] args) throws IOException {
ApplicationContext context=new ClassPathXmlApplicationContext("Beans.xml");
UserService userService= (UserService) context.getBean("userService");
System.out.println(userService.selectUser().size());
}
}

MyBatis-Spring整合之方式3的更多相关文章

  1. springMVC+mybatis+spring整合案例

    1.web.xml a:配置spring监听,使web容器在启动时加载spring的applicationContext.xml <listener> <listener-class ...

  2. springMVC+MyBatis+Spring 整合(3)

    spring mvc 与mybatis 的整合. 加入配置文件: spring-mybaits.xml <?xml version="1.0" encoding=" ...

  3. SpringMVC+Mybatis+Spring整合

    Maven引入需要的JAR包 pom.xml <properties> <!-- spring版本号 --> <spring.version>4.0.2.RELEA ...

  4. MyBatis Spring整合配置映射接口类与映射xml文件

    本文转自http://blog.csdn.net/zht666/article/details/38706083 Spring整合MyBatis使用到了mybatis-spring,在配置mybati ...

  5. Mybatis——Spring整合

    一.引入依赖 Spring的相关jar包 mybatis-3.4.1.jar mybatis-spring-1.3.0.jar mysql-connector-java-5.1.37-bin.jar ...

  6. springMVC+MyBatis+Spring 整合(4) ---解决Spring MVC 对AOP不起作用的问题

    解决Spring MVC 对AOP不起作用的问题 分类: SpringMVC3x+Spring3x+MyBatis3x myibaits spring J2EE2013-11-21 11:22 640 ...

  7. Mybatis+Spring整合后Mapper测试类编写

    public class UserMapperTest { private ApplicationContext applicationContext; @Before public void ini ...

  8. springmvc+mybatis+spring 整合源码项目

    A集成代码生成器 [正反双向(单表.主表.明细表.树形表,开发利器)+快速构建表单; freemaker模版技术 ,0个代码不用写,生成完整的一个模块,带页面.建表sql脚本,处理类,service等 ...

  9. springmvc+mybatis+spring 整合

    获取[下载地址]   [免费支持更新]三大数据库 mysql  oracle  sqlsever   更专业.更强悍.适合不同用户群体[新录针对本系统的视频教程,手把手教开发一个模块,快速掌握本系统] ...

  10. springmvc+mybatis+spring 整合 bootstrap

    获取[下载地址]   [免费支持更新]三大数据库 mysql  oracle  sqlsever   更专业.更强悍.适合不同用户群体[新录针对本系统的视频教程,手把手教开发一个模块,快速掌握本系统] ...

随机推荐

  1. google protocol 入门 demo

    ubunbu系统下google protobuf的安装 说明: 使用protobuf时需要安装两部分: 第一部分为*.proto文件的编译器,它负责把定义的*.proto文件生成对应的c++类的.h和 ...

  2. AE 打开Shp文件

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  3. NIO 和BIO

    讲讲NIO? 传统的IO流是阻塞式的,会一直监听一个ServerSocket,在调用read等方法时,他会一直等到数据到来或者缓冲区已满时才返回.调用accept也是一直阻塞到有客户端连接才会返回.每 ...

  4. JS的冒泡事件

      在一个对象上触发某类事件(比如单击onclick事件),如果此对象定义了此事件的处理程序,那么此事件就会调用这个处理程序,如果没有定义此事件处理程序或者事件返回true,那么这个事件会向这个对象的 ...

  5. vs code使用指南

    https://blog.csdn.net/weixin_45601379/article/details/100550421

  6. Gol流程控制

    条件语句 if语句 if 布尔表达式 { }else 布尔表达式{ }else{ } if语句后的{,一定要和if条件写在同一行,否则报错 else一定要在if语句}之后,不能自己另起一行 if语句变 ...

  7. itext操作表单域导出PDF,俗称扣模板

    /** * templateUrl 模板文件路径,包含文件名 * targetUrl 目标路径 * dateMap 填充数据 */public class CreatePdfUtil { public ...

  8. C语言各语句的作用

    #include <stdio.h> 在使用标准函数库中的输入输出函数时,编译系统要求程序提供有关的信息(例如对这些输入输出函数的声明),#include<stdio.h>的作 ...

  9. 番外:如何克隆可刷新的PDB(Refreshable PDB)

    基于版本:19c (12.2.0.3) AskScuti 创建方法:克隆创建 对应路径:属于克隆.PDB类型为:Refreshable 相关系列请参考<Oracle创建PDB列表文章> 注 ...

  10. WPF学习笔记三之绑定

    1.绑定模式 <TextBlock Margin="10" Text="LearningHard" Name="lbtext" Fon ...