这两天开始写ssm项目了,具体的配置在上一个ssm博客写过啦。
这里帮自己记录一下ssm项目的运行流程,方便之后复习。
比如首先,我们在浏览器上面输入url对应 分类list (admin_category_list)
那么这时候 由于咱在web.xml中配置好了把所有的访问全都拦截给DispatcherServlet处理:
web.xml:
DispatcherServlet有根据SpringMVC的配置,把这次的请求教给CategoryController处理:
SpringMVC:
而在CategoryController中,通过注解的方式,给CategoryService注入了CategoryServiceImal(前者本来是接口的)。在实例化后者的时候又注入了CategoryMapper。
package com.how2java.tmall.service.impl;
import com.how2java.tmall.mapper.CategoryMapper;
import com.how2java.tmall.pojo.Category;
import com.how2java.tmall.service.CategoryService;
import com.how2java.tmall.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class CategoryServiceImpl implements CategoryService {
@Autowired
CategoryMapper categoryMapper;
public List<Category> list(Page page){
return categoryMapper.list(page);
};
public int total(){
return categoryMapper.total();
}
public void add(Category category){
categoryMapper.add(category);
}
public void delete(int id){
categoryMapper.delete(id);
}
public Category get(int id){
return categoryMapper.get(id);
}
public void update(Category category){
categoryMapper.update(category);
}
}
然后根据ApplicationContext.xml中的配置信息,将CategoryMapper和CategoryMapper.xml关联起来了。就可以使用我们在xml中写好的sql语句啦。
然后回到Controller里面,根据注解的映射去调用list方法,在list方法中,访问CategoryService,并获取数据,并把数据放在"cs"上,接着服务端跳转到listCategory.jsp去。
这里能跳到listCategory.jsp去是因为咱在SpringMVC中配置好的,相当于跳转的是 /WEB-INF/jsp/admin/listCategory.jsp
然后就在jsp页面显示我们的数据了。
这就是整个ssm的一次查询的流程。
因篇幅问题不能全部显示,请点此查看更多更全内容