SSM框架整合及简单的crud(二)

版权声明: https://blog.csdn.net/weixin_41716049/article/details/84071983

分页jar包:https://download.csdn.net/download/weixin_41716049/10785021

ssm整合jar包:https://download.csdn.net/download/weixin_41716049/10785016

分析:ssm整合思路

dao层

    sqlmapconfig.xml可以为空,可以不存在

    applicationContext-dao.xml

    数据源;sqlsessionFactory

    别名

    mapper扫描器

service层

     applicationContext-service 。xml

     扫描器:@Service

     事务

web层

     springMvc.xml

     扫描器@controller

     注解驱动

     视图解析器

   (异常处理器,拦截器,文件解析器)

web.xml

    前端控制器

     监听器

一,步骤:

1.创建web工程

2.添加jar,mybatis mybatis扩展包,spring mybatis和spring整合包,springmvc

3.添加配置文件

4.引入资源文件

jsp     js   图片  css  分页标签

Controller层      

 // 获取分页数据

             PageBean pageBean = customerService.findall(queryVo); //调用分页的方法返回pagebean

             model.addAttribute("page", pageBean);//放在域中

             return "customer";//返回页面

service层      

 @Autowired

       private CustomerMapper customerMapper;

       

       public PageBean findall(QueryVo queryVo) {

             PageBean pageBean =new PageBean<Customer>();

             

             List<Customer> list = customerMapper.findall(queryVo);//查询所有数据

             int totalCount = customerMapper.totalCount(queryVo);//查询总条数

             //封装数据到pageBean

             pageBean.setCurrentPage(queryVo.getCurrentPage());

             pageBean.setList(list);

             pageBean.setPageSize(queryVo.getPageSize());

             pageBean.setTotalCount(totalCount);

             return pageBean;

       }

mapper层       

public List<Customer> findall(QueryVo QueryVo);

       public int totalCount(QueryVo QueryVo);

mapper.xml     parameterType:传过来的数据类型    resultType:返回去的数据类型   详情看项目文件

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE mapper

PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"

"http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="cn.itcast.ssm.mapper.CustomerMapper">

       <select id="findall" parameterType="QueryVo" resultType="Customer">

              select

             cust_id,       

             cust_name,     

             cust_user_id,  

             cust_create_id,

             b1.dict_item_name  cust_source,  

             b2.dict_item_name cust_industry,

             b3.dict_item_name cust_level,

             cust_linkman,  

             cust_phone,    

             cust_mobile,   

             cust_zipcode,  

             cust_address,  

             cust_createtime

       from customer c left JOIN base_dict b1   on c.cust_source=b1.dict_id

                    left JOIN base_dict b2   on c.cust_industry=b2.dict_id

                                 left JOIN base_dict b3   on c.cust_level=b3.dict_id

        <include refid="aaa"></include>

             LIMIT #{start},#{pageSize}

       </select>

       <select id="totalCount" parameterType="QueryVo" resultType="int">

             select count(*) from customer

             <include refid="aaa" />

       </select>

       <sql id="aaa">

             <where>

                    <if test="custName!=null and custName !=''">

                           and cust_name LIKE '%${custName}%'

                    </if>

                    <if test="custSource!=null and custSource!=''">

                           AND cust_source=#{custSource}

                    </if>

                    <if test="custIndustry!=null and custIndustry!=''">

                           AND cust_industry=#{custIndustry}

                    </if>

                    <if test="custLevel!=null and custLevel!=''">

                           AND cust_level=#{custLevel}

                    </if>

             </where>

       </sql>

二,开发

每一个容器只能加载一个properties文件

spring容器 监听器加载的    父容器不能访问子容器的对象,子容器可以访问父容器对象

猜你喜欢

转载自blog.csdn.net/weixin_41716049/article/details/84071983