博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
说说自己对ssm整合的看法
阅读量:4229 次
发布时间:2019-05-26

本文共 515 字,大约阅读时间需要 1 分钟。

最简单的说就是mybatis写Dao层,springmvc写视图层,然后通过spring耦合

单独使用mybatis的时候,我们总是要去获得sqlSession,整合的时候,spring配置文件里已经注入了,在服务层中,我们只要注入Mapper就可以使用了,

具体怎么配置我就不说了

在服务层注入持久层的mapper对象

eg

@Autowired

private userMapper userMapper;//这样就可以直接使用该接口的方法了,其他的步骤系统就已经封装好了,

然后再把服务层配置成spring的bean,这样就可以在控制层中使用服务层了,而不用去new一个对象

eg

在类上面添加

@Service("userService")把UserService配置成Spring的bean,名字为userService

最后,在控制器中注入服务层的接口就可以了

@Autowired

@Qualifier("userService")

private UserService userService;//最好加上Qualifier注解,Autowired是默认按类型查找的,当出现同类型的名字是就会出错。

大概就这样。

转载地址:http://kvjqi.baihongyu.com/

你可能感兴趣的文章
User Mode Linux(R) (Bruce Perens Open Source)
查看>>
Enterprise JavaBeans 3.0 (5th Edition)
查看>>
Eclipse 3 Live
查看>>
Java P2P Unleashed: With JXTA, Web Services, XML, Jini, JavaSpaces, and J2EE
查看>>
Java(TM) Network Programming and Distributed Computing
查看>>
Java Cookbook
查看>>
Intelligent Agent Software Engineering
查看>>
Project Management Training
查看>>
Microsoft Reporting Services in Action
查看>>
Successful Software Development (2nd Edition)
查看>>
How to Design Programs: An Introduction to Programming and Computing
查看>>
Beginning Relational Data Modeling, Second Edition
查看>>
Winternals Defragmentation, Recovery, and Administration Field Guide
查看>>
Video Conferencing over IP : Configure, Secure, and Troubleshoot
查看>>
Pro ASP.NET 2.0 Website Programming
查看>>
Disassembling Code : IDA Pro and SoftICE
查看>>
Building Online Communities With Drupal, phpBB, and WordPress
查看>>
C# 2.0 : The Complete Reference
查看>>
Digital Character Animation 3
查看>>
Flash 8 Cookbook
查看>>