开始搭建
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>
<plugin interceptor="com.github.pagehelper.PageHelper">
<property name="dialect" value="mysql"/>
</plugin>
</plugins>
3.在代码中使用
ApplicationContext context =
new ClassPathXmlApplicationContext("classpath:spring/applicationContext-dao.xml");
TbItemMapper tbItemMapper = context.getBean(TbItemMapper.class);
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.测试
- 先开启zookeeper
- 开始二个tomcat