SSM项目layui分页实例

最近学了layui,发现其中的分页挺有意思的,所以整理了一下,一遍自己随时查看。(官方文档上已经很详细了,当中有不足的地方欢迎大家指出)

关于前台的js文件,css样式,js样式,大家可以到官网下

本人使用的是oracle数据库

我先贴出前台界面

SSM项目layui分页实例_第1张图片

spring和spring-mvc,mybatis大家需要的jar包,有需要的可以联系我。

SSM项目layui分页实例_第2张图片

这里使用到了json传数据,所以需要json的jar包

最关键的代码就要来了

1、前台jsp界面

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 
 4 
 5 
 6 
 7 Insert title here
 8  9     charset="utf-8" rel="stylesheet" />
10 
12 
14 
19 
20 class="layui-layout-body">
21     class="layui-table"
22         lay-data="{height:'full', url:'findallEmp.do',page:true,limit:5,limits:[3,5,10,15]}"
23         lay-filter="test1">
24252627282930313233
编号 雇员 工作 入职日期 工资
34 35

 

2、界面跳转到.do

 1 package com.llh.controller;
 2 
 3 import java.util.List;
 4 
 5 import javax.annotation.Resource;
 6 
 7 import org.springframework.context.annotation.Scope;
 8 import org.springframework.stereotype.Controller;
 9 import org.springframework.web.bind.annotation.RequestMapping;
10 import org.springframework.web.bind.annotation.ResponseBody;
11 
12 import com.llh.entity.EmpInfo;
13 import com.llh.service.EmpService;
14 
15 import net.sf.json.JSONArray;
16 
17 
18 @Controller
19 @Scope("prototype")
20 public class EmpController {
21 
22     @Resource
23     private EmpService empService;
24 
25     @RequestMapping(value="findallEmp",produces="text/html;charset=utf-8")
26     public @ResponseBody String findallEmp( int page, int limit){
27         int before = limit * (page - 1) + 1;
28         int after = page * limit;
29         List eilist = empService.findAllPage(before, after);
30         int count = empService.count();
31         JSONArray json = JSONArray.fromObject(eilist);
32         String js = json.toString();
33         String jso = "{\"code\":0,\"msg\":\"\",\"count\":"+count+",\"data\":"+js+"}";//转为layui需要的json格式
34         return jso;
35     }
36 }

3、自动装配的service类

 1 package com.llh.service;
 2 
 3 import java.util.List;
 4 
 5 import javax.annotation.Resource;
 6 
 7 import org.apache.ibatis.annotations.Param;
 8 import org.springframework.stereotype.Service;
 9 import org.springframework.transaction.annotation.Transactional;
10 
11 import com.llh.dao.EmpDao;
12 import com.llh.entity.EmpInfo;
13 @Service
14 @Transactional
15 public class EmpService implements EmpDao{
16     
17     @Resource
18     private EmpDao empDao;
19     
20     /**
21      * 查询数据
22      */
23     public List findAllPage(@Param("before") int before,@Param("after") int after){
24         return empDao.findAllPage(before, after);
25     }
26     /**
27      * 查询条数
28      */
29     public int count(){
30         return empDao.count();
31     }
32     
33 }

4、实现dao接口

 1 package com.llh.dao;
 2 
 3 import java.util.List;
 4 
 5 import org.apache.ibatis.annotations.Param;
 6 
 7 import com.llh.entity.EmpInfo;
 8 
 9 public interface EmpDao {
10 
11     public List findAllPage(@Param("before") int before,@Param("after") int after);
12     
13     public int count();
14 }

5、mapper.xml监控dao

 1 
 2 DOCTYPE mapper
 3 PUBLIC "-//mybatis.org//DTD mapper 3.0//EN"
 4 "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 5 
 6     
 9     
12 

6、至于spring-mybatis.xml也贴出来一下,供有需要的人来看

 1 
 2 <beans
 3 xmlns="http://www.springframework.org/schema/beans"
 4 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 5 xmlns:context="http://www.springframework.org/schema/context"
 6 xmlns:tx="http://www.springframework.org/schema/tx"
 7 xsi:schemaLocation="http://www.springframework.org/schema/beans
 8 http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
 9 http://www.springframework.org/schema/context
10 http://www.springframework.org/schema/context/spring-context-4.3.xsd
11 http://www.springframework.org/schema/tx
12 http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
13 "
14 >
15 
16 package="com.llh">
17 
18 
19 class="org.apache.commons.dbcp.BasicDataSource">
20     
21     
22     
23     
24 
25 
26 
27 class="org.mybatis.spring.SqlSessionFactoryBean">
28     
29     
30     
31 
32 
33 
34 class="org.mybatis.spring.mapper.MapperScannerConfigurer">
35     
36 
37 
38 
39 class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
40     
41 
42 
43 
44 
45 
46 
47 

7、springmvc.xml的配置

 1 
 2  3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
 4     xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx"
 5     xsi:schemaLocation="http://www.springframework.org/schema/beans
 6 http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
 7 http://www.springframework.org/schema/context
 8 http://www.springframework.org/schema/context/spring-context-4.3.xsd
 9 http://www.springframework.org/schema/mvc
10 http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
11 http://www.springframework.org/schema/tx
12 http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
13 ">
14     package="com.llh">
15     
16     default-servlet-handler />
17 
18 
19 
20     21         class="org.springframework.web.servlet.view.InternalResourceViewResolver">
22         
23         
24     
25 
26      27         class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
28         
29         
30      
31     
32     
33     
34 
35 

8、web.xml实现字符编码,过滤器,spring-mybatis的监听,springmvc的监听

 1 
 2 
 3   PageTestDemo
 4   
 5     index.jsp
 6   
 7    
 8   
 9       contextConfigLocation
10       classpath:spring-mybatis.xml
11   
12   
13   
14   
15       class>org.springframework.web.context.ContextLoaderListenerclass>
16   
17   
18   
19   
20       dispatcherServlet
21       class>org.springframework.web.servlet.DispatcherServletclass>
22     
23           contextConfigLocation
24           classpath:springmvc.xml
25       
26   
27   
28       dispatcherServlet
29       *.do
30   
31   
32   
33   
34       characterEncoding
35       class>org.springframework.web.filter.CharacterEncodingFilterclass>
36       
37           encoding
38           UTF-8
39       
40   
41   
42       characterEncoding
43       /*
44   
45   
46   
47 

------------------------------至此,leyui最简单的分页查询数据就可以了。

 

过后将会更新layui的上传,动态下载。

以及bootstrap的数据表格插件

转载于:https://www.cnblogs.com/javallh/p/llonghu.html

你可能感兴趣的:(SSM项目layui分页实例)