发表于: 2017-10-02 23:52:11
1 828
今天完成的任务
照着范例打了一遍ssm分页演示
然而还是不是很理解
首先是创建分页类
public class Page {
int start=0;
int count = 5;
int last = 0;
public int getStart() {
return start;
}
public void setStart(int start) {
this.start = start;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public int getLast() {
return last;
}
public void setLast(int last) {
this.last = last;
}
public void caculateLast(int total) {
// 假设总数是50,是能够被5整除的,那么最后一页的开始就是45
if (0 == total % count)
last = total - count;
// 假设总数是51,不能够被5整除的,那么最后一页的开始就是50
else
last = total - total % count;
}
}
将调用sql语句的接口categorymapper中的select标签
@Select({"<script>",
"select * from category_",
" <if test='start!=null and count!=null'>",
"limit #{start},#{count}",
"</if>",
"</script>"})
改为如下形式,这是我今天能算掌握的一点..
更该service的接口方法
public interface CategoryService {
List<Category> list();
int total();
List<Category> list(Page page);
}
最后再controller中
// 告诉spring mvc这是一个控制器类
@Controller
@RequestMapping("1")
public class CategoryController {
@Autowired
CategoryService categoryService;
@RequestMapping("listCategory")
public ModelAndView listCategory(Page page){
ModelAndView mav = new ModelAndView();
List<Category> cs= categoryService.list(page);
int total = categoryService.total();
page.caculateLast(total);
// 放入转发参数
mav.addObject("cs", cs);
// 放入jsp路径
mav.setViewName("listCategory");
return mav;
}
}
虽然做出了分页,但是并没有很好的理解这些内容。
今天学习的东西很少...
明天要做的事情
遇到的问题
收获
评论