MY_SSM框架之Java后台+前端之商城项目笔记

2017-01-20  本文已影响180人  _Weak
  1. 配置svn插件
    http://www.cnblogs.com/hongten/archive/2013/04/09/hongten_myeclipse_svn.html

  2. 创建查询并分页

<!-- 1. 在Mybatis配置文件sqlmapConfig中配置pageHelper插件 -->
<!-- 2. 在执行sql语句之前, 添加一个PageHelper.startPage(page,rows) -->
<plugins>
    <!-- com.github.pagehelper为PageHelper类所在包名 -->
    <plugin interceptor="com.github.pagehelper.PageHelper">
        <!-- 设置数据库类型 Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL六种数据库-->        
        <property name="dialect" value="mysql"/>
    </plugin>
</plugins>
分页实例

@Test
    public void testPageHelper()
        //创建一个spring容器
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:spring/applicationContext-*.xml");
        //从ApplicetionContext中获取Maper对象
        TbItemMapper maper = applicationContext.getBean(TbItemMapper.class);
        //执行查询并分页
        TbItemExample tbItemExample = new TbItemExample();
        //分页处理
        PageHelper.startPage(1, 10);
        List<TbItem> list = maper.selectByExample(tbItemExample);
        for (TbItem tbItem : list) {
            System.out.println(tbItem.getTitle());
        }
        //取分页信息
        PageInfo<TbItem> pageInfo = new PageInfo<>(list);
        long total = pageInfo.getTotal();
        System.out.println("共有商品: "+total);
    }
//1. 初始化spring容器
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:spring/applicationContext-*.xml");        
<!-- 解决静态资源被拦截问题 js/css资源映射 -->
    <mvc:resources location="/js/" mapping="/js/**"/>
    <mvc:resources location="/css/" mapping="/css/**"/>
/**
     * 一个handler代表一个请求路径
     */
    @RequestMapping("/{page}")
    public String showPage(@PathVariable String page){
        return page;
    }
上一篇 下一篇

猜你喜欢

热点阅读