springmvc和mybatis整合
在mybatis的笔记学习中,是通过写测试程序得到ApplicationContext然后就使用mapper来操作数据库。

这一次通过web开发形式。链接访问。
1、配置文件的编写
数据源,SqlMapConfig.xml,mapper.xml(由逆向工程产生mapper)
2、加载spring容器
web.xml中加入如下配置。spring管理mapper接口。

3、测试controller
代码controller(自动注入mapper)

jsp

4、测试结果
访问:http://localhost:8080/mybatis_spring/searchUser.action
显示:

这个测试缺少service层。
5.service层
简单实现。(用户名模糊搜索)
接口

接口实现

UserService
-----UserService的实现类加到spring容器。xml配置文件。

-----controller 注入

结果(user.jsp)


浙公网安备 33010602011771号