开始搭建

1.创建web的后台页面

注意jsp文件要放到WEB-INF下面.
删除index.jsp  使直接请求localhost:8080到主页面
配置资源映射

2.配置servlet的请求

请求一个页面 返回那个页面
    @RequestMapping("/{page}")
    public String showPage(@PathVariable String page) {
        return page;
    }

3.分页插件PageHelper

该插件目前支持Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL六种数据库分页。

1.添加分页的jar包

pagehelper-fix
<pagehelper.version>3.4.2-fix</pagehelper.version>
导入pagehelper的模块

2.在Mybatis配置xml中配置拦截器插件

    <plugins>
        <!-- com.github.pagehelper为PageHelper类所在包名 -->
        <plugin interceptor="com.github.pagehelper.PageHelper">
            <!-- 设置数据库类型 Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL六种数据库-->
            <property name="dialect" value="mysql"/>
        </plugin>
    </plugins>

3.在代码中使用

        ApplicationContext context =
                new ClassPathXmlApplicationContext("classpath:spring/applicationContext-dao.xml");
//      从容器中回去Dao
        TbItemMapper tbItemMapper = context.getBean(TbItemMapper.class);

//      在sql语句执行之前设置查询信息
        PageHelper.startPage(1,10);

//      执行查询
        TbItemExample itemExample = new TbItemExample();
        List<TbItem> tbItems = tbItemMapper.selectByExample(itemExample);

        PageInfo<TbItem> pageInfo = new PageInfo<>(tbItems);
        System.out.println(pageInfo.getTotal());
        System.out.println(pageInfo.getPages());
        System.out.println(pageInfo.getList());

4.在common模块中创建一个分页的类pojo

{  total:”2”,  rows:[{“id”:”1”,”name”:”张三”},{“id”:”2”,”name”:”李四”}]   }
    EasyUIDataGridResult
        private long tolal;
        private List rows;

5.在service中进行使用

    @Override
    public EasyUIDataGridResult getItemList(int page, int rows) {
        //设置分页信息
        PageHelper.startPage(page, rows);
        //执行查询
        TbItemExample example = new TbItemExample();
        List<TbItem> list = itemMapper.selectByExample(example);
        //取分页信息
        PageInfo<TbItem> pageInfo = new PageInfo<>(list);

        //创建返回结果对象
        EasyUIDataGridResult result = new EasyUIDataGridResult();
        result.setTotal(pageInfo.getTotal());
        result.setRows(list);
        return result;
    }

6.发布服务

还是原来的那个
    <!-- 使用dubbo发布服务 -->
    <!-- 提供方应用信息,用于计算依赖关系 -->
    <dubbo:application name="shopping_manager" />
    <dubbo:registry protocol="zookeeper"
                    address="192.168.0.5:2181"/>

    <!-- 用dubbo协议在20880端口暴露服务 -->
    <dubbo:protocol name="dubbo" port="20880" />
    <!-- 声明需要暴露的服务接口 -->
    <dubbo:service interface="com.matteo.service.ItemService" ref="itemService"/>

7.测试

  1. 先开启zookeeper
  2. 开始二个tomcat

results matching ""

    No results matching ""