新工做上班九天心得(附 bootstrap分页写法)

        新工做上班第九天了。写写本身的心得。      
css

        新工做第三天,分配了一个项目,一个开发组长,三个开发人员,一个月完成。开发人员:1. 苏:工做经验比我还多(10年),2. 曾:工做一年多。3.我。      
html

         第四天:讨论开发框架,论坛了苏从网站上自动生成代码的那一套。我的以为很差用。开发组长周看起来像打酱油的,开发框架本身都没有,还要咱们本身拿主意。       
前端

         第五天:组长周给了一套他本身用过的开发代码,在resin上能够启动,可是只有源代码,没有用Eclipse搭起来的项目。苏和周一致说用任何编辑器写好代码之后,放到resin里面就跑。我以为难以想象。(进入工做发现有太多难以想象了!)怎么可能不编译调试。我用Eclipse新建了一个项目,导入了周给的代码。项目能启动,就是首页地址有的请求路径不对。他的代码全是放到root下面的,而我新建的项目是在个人项目名称下面。               
        第二周,      
        周一:这个不太懂的周说:“你这仍是适应不了这个开发环境,这样你今天仍是不能作事!”我靠!通过研究,在tomcat里面改个配置便可                             
        <Context path="" docBase="E:/code/apache-tomcat-6.0.39kaowu/webapps/eapp" debug="0" reloadable="true"/>               
        docBase路径不能有空格。               
        开始作登录,沿用Apache shiro 的登录 还比较顺利             
         周二,作表单录入,直接controller调用dao保存方法比较快。       
        (题外:他们也是用的springmvc hibernate 可是能够直接请求XX.jsp,跟我以前作过的项目彻底不同,为此研究了好久,发现他们的文件是放在webroot下面 不在web-inf目录下面。原来放在webroot下面是通过过滤器,可是不通过mvc 的控制器的。)         
        另外发现:在webroot下面时相对路径很差使,是否是要在web-inf下面才有用呢,未得验证。               
        周三,作列表。我原来用的页面前台都是easyui。此次的项目要兼容手机端,html5。因而美工妹子曾用了bootcss.(比我有见识,很是流行的前端有easyui,bootcss,ext js).                
        用bootstrap 表格的时候开始是客户端分页,在妹子的帮助下,找到了文档 http://bootstrap-table.wenzhixin.net.cn/examples/                
        找到了传到后台的每页条数Limit,和记录开始数Offset。            
        开始封装。分享一下个人代码。从bootstrap table 获取页码和页数,并交给后台处理。html5

$('#table').bootstrapTable({
            url: '<%=path%>/FeedList.cqzk',
            striped: true,
            pagination: true,
            pageList: [3,5,20],
            pageSize:3,
            pageNumber:1,
            sidePagination:'server',//设置为服务器端分页
            columns: [{
                field: 'title',
                title: '标题'
            }, {
                field: 'creatTime',
                title: '时间'
            } ]
        });



  @RequestMapping(value = "/FeedList.cqzk")
    @ResponseBody
    public String url_ad1(HttpServletRequest request,BootPage page) 
            throws ServletException,IOException,RuntimeException{
        
        @SuppressWarnings("unchecked") 
//        List<Feedback> list = feedBackDao.find("from Feedback");
        BootPage pager = feedBackDao.getByPage("from Feedback",page,null);
        System.out.println((JSONArray.fromObject(pager)).getString(0).toString());
        return      (JSONArray.fromObject(pager)).getString(0).toString(); 
   //   不写.getString(0) 就多一个中括号,返回的就是数组,写了就是返回第一个对象。
    }
    


public BootPage getByPage(String hql,BootPage pager,Map<String, Object> condition){
        if (pager == null) {
            throw new IllegalArgumentException("分页 不能为空!");
        }

        Query q = sessionFactory.getCurrentSession().createQuery(hql);
        q.setFirstResult(pager.getOffset());
        q.setMaxResults(pager.getLimit());

        if (condition != null) {
            q.setProperties(condition);
        }
        pager.setRows(q.list());
        pager.setTotal(this.countAll(hql, condition));
        return pager;
        
    }
    protected Long countAll(String hql, Map<String, Object> condition) {
        if (hql == null) {
            return 0l;
        }
        String tmpHql = hql.toLowerCase();
        String regex = hql.substring(0, tmpHql.indexOf("from"));
        hql = hql.replaceFirst(regex, "select count(*) ");
        Query q = sessionFactory.getCurrentSession().createQuery(hql);
        if (condition != null) {
            q.setProperties(condition);
        }
        return (Long) q.uniqueResult();
    }


public final class BootPage<T> {
    
    protected Long total;
    
    protected List<T> rows;
    
    protected int limit=0;
    
    protected int offset = 0;
    
    protected String order ="asc" ;
相关文章
相关标签/搜索