MyBatis-Spring整合之方式3
通过注解整合
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的更多相关文章
- springMVC+mybatis+spring整合案例
1.web.xml a:配置spring监听,使web容器在启动时加载spring的applicationContext.xml <listener> <listener-class ...
- springMVC+MyBatis+Spring 整合(3)
spring mvc 与mybatis 的整合. 加入配置文件: spring-mybaits.xml <?xml version="1.0" encoding=" ...
- SpringMVC+Mybatis+Spring整合
Maven引入需要的JAR包 pom.xml <properties> <!-- spring版本号 --> <spring.version>4.0.2.RELEA ...
- MyBatis Spring整合配置映射接口类与映射xml文件
本文转自http://blog.csdn.net/zht666/article/details/38706083 Spring整合MyBatis使用到了mybatis-spring,在配置mybati ...
- Mybatis——Spring整合
一.引入依赖 Spring的相关jar包 mybatis-3.4.1.jar mybatis-spring-1.3.0.jar mysql-connector-java-5.1.37-bin.jar ...
- springMVC+MyBatis+Spring 整合(4) ---解决Spring MVC 对AOP不起作用的问题
解决Spring MVC 对AOP不起作用的问题 分类: SpringMVC3x+Spring3x+MyBatis3x myibaits spring J2EE2013-11-21 11:22 640 ...
- Mybatis+Spring整合后Mapper测试类编写
public class UserMapperTest { private ApplicationContext applicationContext; @Before public void ini ...
- springmvc+mybatis+spring 整合源码项目
A集成代码生成器 [正反双向(单表.主表.明细表.树形表,开发利器)+快速构建表单; freemaker模版技术 ,0个代码不用写,生成完整的一个模块,带页面.建表sql脚本,处理类,service等 ...
- springmvc+mybatis+spring 整合
获取[下载地址] [免费支持更新]三大数据库 mysql oracle sqlsever 更专业.更强悍.适合不同用户群体[新录针对本系统的视频教程,手把手教开发一个模块,快速掌握本系统] ...
- springmvc+mybatis+spring 整合 bootstrap
获取[下载地址] [免费支持更新]三大数据库 mysql oracle sqlsever 更专业.更强悍.适合不同用户群体[新录针对本系统的视频教程,手把手教开发一个模块,快速掌握本系统] ...
随机推荐
- 解决sql server2008数据库安装之后,web程序80端口被占用问题(终极方案)
解决sql server2008数据库安装之后,web程序80端口被占用问题(终极方案) 前言:原来电脑上的Apache一直使用正常,在安装sql server2008后,突然发现Apache无法启动 ...
- php中普通类 接口类 抽象类 浅谈
一.普通类 1.关键词:class 类名,继承关键字extends 2.继承:只能实现单继承, 3.多态:子类继承可以实现多种功能 4.封装:类有权限机制,私有的只能自己用,受保护的可以被继承,子类 ...
- 【转】Error,java对常量池来说字符串xxx的UTF8表示过长的解决及其理解
做项目,客户端这里自己模拟json数据时,一时没忍住搞得json字符串太长了(idea上大概有600多行吧),这个问题就蹦出来了.老方法直接google.百度然后看到一堆有关String 字符串常量池 ...
- Execl导出系统
前台代码: <button class="btn btn-warning" type="button" onclick="location.hr ...
- g++运行c++程序提示main()找不到
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o: In function `_start': (.text+0x20) ...
- The number of set(位运算+状态dp)一道十分美妙的题目哦!!!!!!
Given you n sets.All positive integers in sets are not less than 1 and not greater than m.If use the ...
- mysql 查询——逻辑查询
--去重查询 distinct select distinct gander from student; --逻辑查询 and or not --查询18-28之间的数据 select *from s ...
- IDA pro 6.8显示中文字符串的方法
IDA pro 6.8设置显示中文字符串的方法 M4x原创,转载请表明出处http://www.cnblogs.com/WangAoBo/p/7636335.html IDA是一款强大无比的反编译软件 ...
- 整理收集的一些常用java工具类
1.json转换工具 package com.taotao.utils; import java.util.List; import com.fasterxml.jackson.core.JsonPr ...
- wap网站开发小记(转载)
一:网页的一些标记 1:声明 <!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http ...