(二)JAVAEE

SSM整合思路
一、需求分析
a.前端查询后端数据库,将返回到前端展示(例子)
二、建立
1、项目结构

2、在com.ssm工程建立pojo包(MyBatis_M层)
  b.建立实体类(与数据库表字段对应)
3、在com.ssm工程建立dao包
  a.建立Mapper接口文件
  b.建立Mapper.xml映射文件
  c.在resources建立db.properties数据库文件
  d.在resources建立mybatis-config.xml配置文件
i.日志
ii.别名
lll.告诉MyBatis到哪地方去找映射文件
  e.在resources建立spring-dao.xml配置文件
    i.关联数据库文件
    il.配置数据源
    lll.配置MyBatis工厂,整合MyBatis
    vi.Mapper代理开发,Spring自动扫描MyBatis(dao包)接口并装配
4、在com.ssm工程建立Service包(Spring_M层)
  a.建立Service接口文件
    i.抽象方法
  b.建立接口实现类(业务层)
    i.@Autowired注入dao依赖
    ii.实现抽象方法(调用dao层)、返回结果
  c.在resources建立spring-service.xml
    i.扫描Service包
    il.声明事务配置
    lll.aop事务支持
5、在com.ssm工程建立Context包(SpringMVC_C层)
  a.建立Context.java文件
    i.@Autowired注入service依赖
    il.建立方法,将前端V层与service M层关联,返回页面
  b.在resources建立spring-mvc.xml
    i.开启SpringMVC注解驱动
    ii.静态资源默认servlet配置
    lll.配置ViewResolver视图解析器
    vi.配置拦截器
    v.扫描包(controller类)
6、在resources建立Spring整合文件applicationContext.xml
  a.添加Mybatis、spring、SpringMVC三个配置文件
    i.spring-dao.xml
    ii.spring-service.xml
    lll.spring-mvc.xml
7、在webapp\WEB-INF\配置wbe.xml
  a.前端控制器
    i.加载applicationContext.xml
    ii.启动时立即加载servlet
    lll.处理所有URL
  b.处理字符乱码问题
  c.Session过期时间
8、在webapp配置index.jsp(前端页面)
  a.定义链接跳转到wbe.xml-->applicationContext.xml-->spring-mvc.xml-->context.java
告诉MyBatis到哪地方去找映射文件
posted @ 2022-10-05 22:18  九五二七_唐伯虎  阅读(37)  评论(0编辑  收藏  举报