springmvc+mybatis+mysql8+idea+jqgrid前端

一、背景

主要是为了学习jqgrid前端技术,熟练一下前后端交互数据

二、效果图

访问地址:http://localhost:8080/cr/views/jqGridDemo.jsp

三、代码展示

控制层JqGridController.java
@Controller
@RequestMapping("/jqgrid")
public class JqGridController {

    private String page=""; //当前显示页码
    private String rows=""; //每页显示的多少条数
    private Map map;

    @Autowired
    private IJqGridService jqGridService;

    @RequestMapping(value = "/getRoleList", method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public Map getRoleList(String page, String rows){
        //分页查询
        map = jqGridService.getRoleListPage(page, rows);
        return map;
    }

service层

@Service("jqGridService")
@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT)
public class JqGridServiceImpl implements IJqGridService {
    @Autowired
    private IJqGridDao jqGridDao;

    @Override
    public Map getRoleListPage(String page, String rows) {
        Map map = new HashMap<>();

        //总记录,已分页
        List roleListPage = jqGridDao.getRoleListPage((Integer.parseInt(page) - 1)*Integer.parseInt(rows), Integer.parseInt(rows));
        //总记录数count
        String totalRecordCount = jqGridDao.getRoleListCount();
        //总页码
        String totalPage = (Integer.parseInt(totalRecordCount) % Integer.parseInt(rows)==0?(Integer.parseInt(totalRecordCount) / Integer.parseInt(rows)+""):(Integer.parseInt(totalRecordCount) / Integer.parseInt(rows)+1+""));

        map.put("info", roleListPage);
        map.put("totalRecordCount", totalRecordCount);
        map.put("totalPage", totalPage);
        map.put("page", page);
        return map;
    }
}

dao层

public interface IJqGridDao {

    @Select("select * from sys_role order by order_num limit ${page},${rows}")
    List getRoleListPage(@Param("page") Integer page, @Param("rows") Integer rows);

    @Select("select count(*) from sys_role where 1=1")
    String getRoleListCount();
}

页面

<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%
    String path = request.getContextPath();
    System.out.println("path="+path);
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    System.out.println("basePath="+basePath);
%>


    
    我是demo.html页面

    
    
    
    
    

    

    
    
    
    
    
    
    

    
    
    
    
    
    

    
    




你可能感兴趣的:(前端框架学习,mybatis,intellij-idea,前端,jqgrid)