控制器
package com.yl.controller;
import com.github.pagehelper.PageInfo;
import com.yl.bean.Book;
import com.yl.bean.PageBook;
import com.yl.service.IBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;
import java.util.List;
/**
* 图书控制器类
*/
@Controller
@RequestMapping(“/book”)
@SessionAttributes(value = {“pageBook”},types ={PageBook.class} )
public class BookController {
@Autowired
private IBookService bookService;//图书业务层对象
/**
* 查询所有图书
*/
@RequestMapping(“/queryAll”)
public ModelAndView queryAll(int pageCode){
int pc=1;//页码,默认为第一页
int pageSize=3;//页面数据条数
//判断表单页码是否为空
if (pageCode》0){
pc=pageCode;
}
//调用业务层查询所有方法
PageInfo《Book》 pageInfo=bookService.queryAll(pc,pageSize);
ModelAndView modelAndView=new ModelAndView();
modelAndView.addObject(“pageBook”,pageInfo);
modelAndView.setViewName(“index”);
return modelAndView;
}
}
控制器
package com.yl.controller;
import com.github.pagehelper.PageInfo;
import com.yl.bean.Book;
import com.yl.bean.PageBook;
import com.yl.service.IBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;
import java.util.List;
/**
* 图书控制器类
*/
@Controller
@RequestMapping(“/book”)
@SessionAttributes(value = {“pageBook”},types ={PageBook.class} )
public class BookController {
@Autowired
private IBookService bookService;//图书业务层对象
/**
* 查询所有图书
*/
@RequestMapping(“/queryAll”)
public ModelAndView queryAll(int pageCode){
int pc=1;//页码,默认为第一页
int pageSize=3;//页面数据条数
//判断表单页码是否为空
if (pageCode》0){
pc=pageCode;
}
//调用业务层查询所有方法
PageInfo《Book》 pageInfo=bookService.queryAll(pc,pageSize);
ModelAndView modelAndView=new ModelAndView();
modelAndView.addObject(“pageBook”,pageInfo);
modelAndView.setViewName(“index”);
return modelAndView;
}
}
举报