一、需求:
使用springmvc和mybatis完成商品列表查询。

二、整合思路:
springMVC+mybaits的系统架构:

springMVC学习(3)-springMVC和mybatis整合

1步):整合dao层

mybatis和spring整合,通过spring管理mapper接口。使用mapper的扫描器自动扫描mapper接口在spring中进行注册。

2步):整合service层

通过spring管理 service接口。使用配置方式将service接口配置在spring配置文件中。实现事务控制。

3步)整合springmvc 由于springmvc是spring的模块,不需要整合。

所需要的jar包:

数据库驱动包:mysql5.1、mybatis的jar包、mybatis和spring整合包、log4j包、dbcp数据库连接池包、spring3.2所有jar包、jstl包

 

三、开始整合和开发:

1)工程结构:

springMVC学习(3)-springMVC和mybatis整合

springMVC学习(3)-springMVC和mybatis整合

springMVC学习(3)-springMVC和mybatis整合

2)整合dao:

配置sqlMapConfig.xml;

配置applicationContext-dao.xml:(数据源、sqlSessionFactory、mapper扫描器)

逆向工程生成mapper接口、mapper.xml、po类;将生成的文件拷贝至工程中;

编写扩展po类poCustom、以及对应的poCustom.xml和接口poCustom.java;

3)整合Serive:

配置applicationContext-service.xml(配置Service.bean、配置事务)

4)整合springMVC:

配置springMVC.xml(配置处理器映射器、适配器、视图解析器;相关扫描包)

配置web.xml(配置前端控制器、监听器加载spring配置文件(使用通配符))

 

相关代码:

items.java:

 1 package com.cy.po;
 2 
 3 import java.util.Date;
 4 
 5 public class Items {
 6     private Integer id;
 7     private String name;
 8     private Float price;
 9     private String pic;
10     private Date createtime;
11     private String detail;
12     ...
13 
14     getters and setters
15 }
Items.java

相关文章:

  • 2021-09-17
  • 2021-09-23
  • 2021-08-30
  • 2021-08-09
  • 2022-01-31
  • 2021-11-09
  • 2022-12-23
  • 2021-06-20
猜你喜欢
  • 2022-01-22
  • 2021-08-01
  • 2021-06-22
  • 2022-12-23
  • 2022-12-23
  • 2021-08-28
  • 2022-12-23
相关资源
相似解决方案