how2j.cn

下载区
文件名 文件大小
pagehelper-5.1.0-beta2.jar 78k
jsqlparser-1.0.jar 355k
ssm.rar 10m
步骤 1 : 基于前面的知识点   
步骤 2 : 先运行,看到效果,再学习   
步骤 3 : 模仿和排错   
步骤 4 : 效果   
步骤 5 : jar包   
步骤 6 : 修改applicationContext.xml   
步骤 7 : CategoryService   
步骤 8 : CategoryServiceImpl   
步骤 9 : CategoryMapper   
步骤 10 : Category.xml   
步骤 11 : CategoryController   
步骤 12 : MybatisTest   
步骤 13 : 重启tomcat,测试   

步骤 1 :

基于前面的知识点

edit
本知识点基于SSM 分页进行SSM 分页进行是采用手动SQL方式进行,本知识点将采用PageHelper插件进行。
参考: PageHelper和Mybatis整合教程
步骤 2 :

先运行,看到效果,再学习

edit
老规矩,先下载右上角的可运行项目,配置运行起来,确认可用之后,再学习做了哪些步骤以达到这样的效果。
在确保可运行项目能够正确无误地运行之后,再严格照着教程的步骤,对代码模仿一遍。
模仿过程难免代码有出入,导致无法得到期望的运行结果,此时此刻通过比较正确答案 ( 可运行项目 ) 和自己的代码,来定位问题所在。
采用这种方式,学习有效果,排错有效率,可以较为明显地提升学习速度,跨过学习路上的各个槛。

推荐使用diffmerge软件,进行文件夹比较。把你自己做的项目文件夹,和我的可运行项目文件夹进行比较。
这个软件很牛逼的,可以知道文件夹里哪两个文件不对,并且很明显地标记出来
这里提供了绿色安装和使用教程:diffmerge 下载和使用教程
访问页面看到如图所示效果

http://127.0.0.1:8080/ssm/listCategory
效果
因为是第三方插件,所以需要额外的jar包,都在右上角提供了下载:pagehelper-5.1.0-beta2.jar,jsqlparser-1.0.jar
下载后放在WEB-INF/lib下
jar包
步骤 6 :

修改applicationContext.xml

edit
增加38-48的PageHelper插件配置
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation=" http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <context:annotation-config /> <context:component-scan base-package="com.how2java.service" /> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName"> <value>com.mysql.jdbc.Driver</value> </property> <property name="url"> <value>jdbc:mysql://localhost:3306/how2java?characterEncoding=UTF-8</value> </property> <property name="username"> <value>root</value> </property> <property name="password"> <value>admin</value> </property> </bean> <bean id="sqlSession" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="typeAliasesPackage" value="com.how2java.pojo" /> <property name="dataSource" ref="dataSource"/> <property name="mapperLocations" value="classpath:com/how2java/mapper/*.xml"/> <property name="plugins"> <array> <bean class="com.github.pagehelper.PageInterceptor"> <property name="properties"> <!--使用下面的方式配置参数,一行配置一个 --> <value> </value> </property> </bean> </array> </property> </bean> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.how2java.mapper"/> </bean> </beans>
CategoryService去掉total方法和list(Page) 方法
package com.how2java.service; import java.util.List; import com.how2java.pojo.Category; import com.how2java.util.Page; public interface CategoryService { List<Category> list(); }
package com.how2java.service;

import java.util.List;

import com.how2java.pojo.Category;
import com.how2java.util.Page;

public interface CategoryService {

	List<Category> list();
}
步骤 8 :

CategoryServiceImpl

edit
CategoryServiceImpl去掉total方法和list(Page) 方法
package com.how2java.service.impl; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.how2java.mapper.CategoryMapper; import com.how2java.pojo.Category; import com.how2java.service.CategoryService; @Service public class CategoryServiceImpl implements CategoryService{ @Autowired CategoryMapper categoryMapper; public List<Category> list(){ return categoryMapper.list(); } }
CategoryMapper去掉total方法和list(Page) 方法
package com.how2java.mapper; import java.util.List; import com.how2java.pojo.Category; import com.how2java.util.Page; public interface CategoryMapper { public int add(Category category); public void delete(int id); public Category get(int id); public int update(Category category); public List<Category> list(); }
package com.how2java.mapper;
 
import java.util.List;

import com.how2java.pojo.Category;
import com.how2java.util.Page;
 
public interface CategoryMapper {
 
    public int add(Category category);  
       
    public void delete(int id);  
       
    public Category get(int id);  
     
    public int update(Category category);   
       
    public List<Category> list();
      
}
Category.xml去掉total对应的sql语句,list也去掉limit
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.how2java.mapper.CategoryMapper"> <insert id="add" parameterType="Category" > insert into category_ ( name ) values (#{name}) </insert> <delete id="delete" parameterType="Category" > delete from category_ where id= #{id} </delete> <select id="get" parameterType="_int" resultType="Category"> select * from category_ where id= #{id} </select> <update id="update" parameterType="Category" > update category_ set name=#{name} where id=#{id} </update> <select id="list" resultType="Category"> select * from category_ </select> </mapper>
步骤 11 :

CategoryController

edit
CategoryController在调用categoryService.list(); 之前,执行:

PageHelper.offsetPage(page.getStart(),5);

并通过int total = (int) new PageInfo<>(cs).getTotal();获取总数。
其他都不变
package com.how2java.controller; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.support.PagedListHolder; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.how2java.pojo.Category; import com.how2java.service.CategoryService; import com.how2java.util.Page; // 告诉spring mvc这是一个控制器类 @Controller @RequestMapping("") public class CategoryController { @Autowired CategoryService categoryService; @RequestMapping("listCategory") public ModelAndView listCategory(Page page){ ModelAndView mav = new ModelAndView(); PageHelper.offsetPage(page.getStart(),5); List<Category> cs= categoryService.list(); int total = (int) new PageInfo<>(cs).getTotal(); page.caculateLast(total); // 放入转发参数 mav.addObject("cs", cs); // 放入jsp路径 mav.setViewName("listCategory"); return mav; } }
MybatisTest 类注释掉用旧方式分页的代码,其实全部都注释掉了
package com.how2java.test; import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.how2java.mapper.CategoryMapper; import com.how2java.pojo.Category; import com.how2java.util.Page; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("classpath:applicationContext.xml") public class MybatisTest { // @Autowired // private CategoryMapper categoryMapper; // //// @Test // public void testAdd() { // for (int i = 0; i < 100; i++) { // Category category = new Category(); // category.setName("new Category"); // categoryMapper.add(category); // } // // } // // @Test // public void testTotal() { // int total = categoryMapper.total(); // System.out.println(total); // } // // @Test // public void testList() { // Page p = new Page(); // p.setStart(2); // p.setCount(3); // List<Category> cs=categoryMapper.list(p); // for (Category c : cs) { // System.out.println(c.getName()); // } // } }
步骤 13 :

重启tomcat,测试

edit
重启tomcat,访问地址:

http://127.0.0.1:8080/ssm/listCategory?start=5
重启tomcat,测试


HOW2J公众号,关注后实时获知布最新的教程和优惠活动,谢谢。


问答区域    
2019-04-18 ssm分页的时候点击到底以后点击上一页报错
23520105



ssm分页的时候点击到底以后点击上一页报错
下载的案列 没有任何更改
四月 18, 2019 8:45:24 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: Server version:        Apache Tomcat/7.0.93
四月 18, 2019 8:45:24 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: Server built:          Feb 16 2019 17:13:17 UTC
四月 18, 2019 8:45:24 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: Server number:         7.0.93.0
四月 18, 2019 8:45:24 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: OS Name:               Windows 10
四月 18, 2019 8:45:24 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: OS Version:            10.0
四月 18, 2019 8:45:24 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: Architecture:          amd64
四月 18, 2019 8:45:24 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: Java Home:             C:\Java\jre1.8.0_131
四月 18, 2019 8:45:24 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: JVM Version:           1.8.0_131-b11
四月 18, 2019 8:45:24 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: JVM Vendor:            Oracle Corporation
四月 18, 2019 8:45:24 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: CATALINA_BASE:         C:\home\apache-tomcat-7.0.93
四月 18, 2019 8:45:24 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: CATALINA_HOME:         C:\home\apache-tomcat-7.0.93
四月 18, 2019 8:45:24 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:12188
四月 18, 2019 8:45:24 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Dcatalina.base=C:\home\apache-tomcat-7.0.93
四月 18, 2019 8:45:24 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Dcatalina.home=C:\home\apache-tomcat-7.0.93
四月 18, 2019 8:45:24 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Dwtp.deploy=C:\home\apache-tomcat-7.0.93\webapps
四月 18, 2019 8:45:24 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Djava.endorsed.dirs=C:\home\apache-tomcat-7.0.93\endorsed
四月 18, 2019 8:45:24 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Dfile.encoding=GBK
四月 18, 2019 8:45:24 上午 org.apache.catalina.core.AprLifecycleListener lifecycleEvent
信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Java\jre1.8.0_131\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Java/jre1.8.0_131/bin/server;C:/Java/jre1.8.0_131/bin;C:/Java/jre1.8.0_131/lib/amd64;C:\Program Files (x86)\NetSarang\Xshell 6\;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;D:\音王文件\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\TortoiseSVN\bin;C:\Java\jdk1.8.0_131\bin;C:\home\apache-maven-3.5.4\bin;C:\P;C:\Users\admin\AppData\Roaming\npm;%USERPROFILE%\AppData\Local\Microsoft\WindowsApps;;C:\home\eclipse;;.
四月 18, 2019 8:45:24 上午 org.apache.coyote.AbstractProtocol init
信息: Initializing ProtocolHandler ["http-bio-8080"]
四月 18, 2019 8:45:24 上午 org.apache.coyote.AbstractProtocol init
信息: Initializing ProtocolHandler ["ajp-bio-8009"]
四月 18, 2019 8:45:24 上午 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 442 ms
四月 18, 2019 8:45:24 上午 org.apache.catalina.core.StandardService startInternal
信息: Starting service Catalina
四月 18, 2019 8:45:24 上午 org.apache.catalina.core.StandardEngine startInternal
信息: Starting Servlet Engine: Apache Tomcat/7.0.93
四月 18, 2019 8:45:24 上午 org.apache.catalina.loader.WebappClassLoaderBase validateJarFile
信息: validateJarFile(C:\home\apache-tomcat-7.0.93\webapps\shiro\WEB-INF\lib\servlet-api-3.0.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/servlet/Servlet.class
四月 18, 2019 8:45:24 上午 org.apache.catalina.loader.WebappClassLoaderBase validateJarFile
信息: validateJarFile(C:\home\apache-tomcat-7.0.93\webapps\shiro\WEB-INF\lib\servlet-api.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/servlet/Servlet.class
四月 18, 2019 8:45:28 上午 org.apache.catalina.startup.TaglibUriRule body
信息: TLD skipped. URI: http://java.sun.com/jstl/core_rt is already defined
四月 18, 2019 8:45:28 上午 org.apache.catalina.startup.TaglibUriRule body
信息: TLD skipped. URI: http://java.sun.com/jstl/core is already defined
四月 18, 2019 8:45:28 上午 org.apache.catalina.startup.TaglibUriRule body
信息: TLD skipped. URI: http://java.sun.com/jsp/jstl/core is already defined
四月 18, 2019 8:45:28 上午 org.apache.catalina.startup.TaglibUriRule body
信息: TLD skipped. URI: http://java.sun.com/jstl/fmt_rt is already defined
四月 18, 2019 8:45:28 上午 org.apache.catalina.startup.TaglibUriRule body
信息: TLD skipped. URI: http://java.sun.com/jstl/fmt is already defined
四月 18, 2019 8:45:28 上午 org.apache.catalina.startup.TaglibUriRule body
信息: TLD skipped. URI: http://java.sun.com/jsp/jstl/fmt is already defined
四月 18, 2019 8:45:28 上午 org.apache.catalina.startup.TaglibUriRule body
信息: TLD skipped. URI: http://java.sun.com/jsp/jstl/functions is already defined
四月 18, 2019 8:45:28 上午 org.apache.catalina.startup.TaglibUriRule body
信息: TLD skipped. URI: http://jakarta.apache.org/taglibs/standard/permittedTaglibs is already defined
四月 18, 2019 8:45:28 上午 org.apache.catalina.startup.TaglibUriRule body
信息: TLD skipped. URI: http://jakarta.apache.org/taglibs/standard/scriptfree is already defined
四月 18, 2019 8:45:28 上午 org.apache.catalina.startup.TaglibUriRule body
信息: TLD skipped. URI: http://java.sun.com/jstl/sql_rt is already defined
四月 18, 2019 8:45:28 上午 org.apache.catalina.startup.TaglibUriRule body
信息: TLD skipped. URI: http://java.sun.com/jstl/sql is already defined
四月 18, 2019 8:45:28 上午 org.apache.catalina.startup.TaglibUriRule body
信息: TLD skipped. URI: http://java.sun.com/jsp/jstl/sql is already defined
四月 18, 2019 8:45:28 上午 org.apache.catalina.startup.TaglibUriRule body
信息: TLD skipped. URI: http://java.sun.com/jstl/xml_rt is already defined
四月 18, 2019 8:45:28 上午 org.apache.catalina.startup.TaglibUriRule body
信息: TLD skipped. URI: http://java.sun.com/jstl/xml is already defined
四月 18, 2019 8:45:28 上午 org.apache.catalina.startup.TaglibUriRule body
信息: TLD skipped. URI: http://java.sun.com/jsp/jstl/xml is already defined
四月 18, 2019 8:45:28 上午 org.apache.catalina.startup.TldConfig execute
信息: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
四月 18, 2019 8:45:28 上午 org.apache.catalina.core.ApplicationContext log
信息: No Spring WebApplicationInitializer types detected on classpath
四月 18, 2019 8:45:28 上午 org.apache.catalina.core.ApplicationContext log
信息: Initializing Spring root WebApplicationContext
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
四月 18, 2019 8:45:29 上午 org.apache.catalina.core.ApplicationContext log
信息: Initializing Spring FrameworkServlet 'mvc-dispatcher'
四月 18, 2019 8:45:30 上午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory C:\home\apache-tomcat-7.0.93\webapps\docs
四月 18, 2019 8:45:31 上午 org.apache.catalina.startup.TldConfig execute
信息: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
四月 18, 2019 8:45:31 上午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deployment of web application directory C:\home\apache-tomcat-7.0.93\webapps\docs has finished in 931 ms
四月 18, 2019 8:45:31 上午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory C:\home\apache-tomcat-7.0.93\webapps\examples
四月 18, 2019 8:45:33 上午 org.apache.catalina.startup.TldConfig execute
信息: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
四月 18, 2019 8:45:33 上午 org.apache.catalina.core.ApplicationContext log
信息: ContextListener: contextInitialized()
四月 18, 2019 8:45:33 上午 org.apache.catalina.core.ApplicationContext log
信息: SessionListener: contextInitialized()
四月 18, 2019 8:45:33 上午 org.apache.catalina.core.ApplicationContext log
信息: ContextListener: attributeAdded('StockTicker', 'async.Stockticker@5d14122a')
四月 18, 2019 8:45:33 上午 org.apache.catalina.core.ApplicationContext log
信息: ContextListener: attributeAdded('org.apache.jasper.compiler.TldLocationsCache', 'org.apache.jasper.compiler.TldLocationsCache@15896132')
四月 18, 2019 8:45:33 上午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deployment of web application directory C:\home\apache-tomcat-7.0.93\webapps\examples has finished in 1,635 ms
四月 18, 2019 8:45:33 上午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory C:\home\apache-tomcat-7.0.93\webapps\host-manager
四月 18, 2019 8:45:34 上午 org.apache.catalina.startup.TldConfig execute
信息: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
四月 18, 2019 8:45:34 上午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deployment of web application directory C:\home\apache-tomcat-7.0.93\webapps\host-manager has finished in 906 ms
四月 18, 2019 8:45:34 上午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory C:\home\apache-tomcat-7.0.93\webapps\manager
四月 18, 2019 8:45:34 上午 org.apache.catalina.startup.TldConfig execute
信息: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
四月 18, 2019 8:45:34 上午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deployment of web application directory C:\home\apache-tomcat-7.0.93\webapps\manager has finished in 836 ms
四月 18, 2019 8:45:34 上午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory C:\home\apache-tomcat-7.0.93\webapps\ROOT
四月 18, 2019 8:45:35 上午 org.apache.catalina.startup.TldConfig execute
信息: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
四月 18, 2019 8:45:35 上午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deployment of web application directory C:\home\apache-tomcat-7.0.93\webapps\ROOT has finished in 837 ms
四月 18, 2019 8:45:35 上午 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["http-bio-8080"]
四月 18, 2019 8:45:35 上午 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["ajp-bio-8009"]
四月 18, 2019 8:45:35 上午 org.apache.catalina.startup.Catalina start
信息: Server startup in 11029 ms
四月 18, 2019 8:46:24 上午 org.apache.jasper.compiler.TldLocationsCache tldScanJar
信息: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
四月 18, 2019 8:48:13 上午 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet [mvc-dispatcher] in context with path [/shiro] threw exception [Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException: 
### Error querying database.  Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-5,5' at line 8
### The error may exist in file [C:\home\apache-tomcat-7.0.93\webapps\shiro\WEB-INF\classes\com\how2java\mapper\EquipmentMapper.xml]
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: select      id, ip, account_name, number, port, seat, tag, description, out_time,   in_time, is_time,   camera_type, is_start, create_date        from equipment order by id desc        limit ?,?
### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-5,5' at line 8
; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-5,5' at line 8] with root cause
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-5,5' at line 8
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
	at com.mysql.jdbc.Util.getInstance(Util.java:381)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542)
	at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1734)
	at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:995)
	at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:56)
	at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:70)
	at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:57)
	at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:267)
	at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:141)
	at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:105)
	at com.github.pagehelper.PageInterceptor.intercept(PageInterceptor.java:143)
	at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:57)
	at com.sun.proxy.$Proxy30.query(Unknown Source)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:101)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:95)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:386)
	at com.sun.proxy.$Proxy8.selectList(Unknown Source)
	at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:205)
	at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:124)
	at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:90)
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:40)
	at com.sun.proxy.$Proxy12.getByPageEquipment(Unknown Source)
	at com.how2java.service.EquipmentService.getByPageEquipment(EquipmentService.java:35)
	at com.how2java.controller.EquipmentController.member(EquipmentController.java:36)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:743)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:672)
	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:82)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:933)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:867)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:951)
	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:842)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:827)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)
	at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
	at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
	at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
	at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
	at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
	at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
	at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
	at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:343)
	at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:260)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:494)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:1025)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1137)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:319)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Unknown Source)



1 个答案

丽丽哒云儿 答案时间:2019-05-10
上一节讨论区能找到答案



回答已经提交成功,正在审核。 请于 我的回答 处查看回答记录,谢谢
答案 或者 代码至少填写一项, 如果是自己有问题,请重新提问,否则站长有可能看不到





2018-09-09 请问为什么传入了要count而start却要从page拿
不谈了
PageHelper.offsetPage(page.getStart(),5) 全部从page或全部都是传参行吗?




1 个答案

1332333 答案时间:2019-01-25
因为start是会变的,而count是固定的值; start在jsp页面有一个重新赋值的过程



回答已经提交成功,正在审核。 请于 我的回答 处查看回答记录,谢谢
答案 或者 代码至少填写一项, 如果是自己有问题,请重新提问,否则站长有可能看不到




2018-08-03 请问这个插件是查询出所有记录然后进行分页吗?
2018-07-15 如果加上条件查询的分页就好了
2018-04-18 如果在首页继续点上一页sql就会报错
2018-01-31 这要什么参数啊
2017-12-20 关于SSM-PageHelper和不用分页框架的对比提问
2017-11-24 这个 插件可以选择跳转到多少页吗
2017-11-03 对比答案发现MybatisTest.java有修改没有写出来




提问之前请登陆
提问已经提交成功,正在审核。 请于 我的提问 处查看提问记录,谢谢
关于 JAVA 框架-SSM-PageHelper 的提问

尽量提供截图代码异常信息,有助于分析和解决问题。 也可进本站QQ群交流: 1001964108
提问尽量提供完整的代码,环境描述,越是有利于问题的重现,您的问题越能更快得到解答。
对教程中代码有疑问,请提供是哪个步骤,哪一行有疑问,这样便于快速定位问题,提高问题得到解答的速度
在已经存在的几千个提问里,有相当大的比例,是因为使用了和站长不同版本的开发环境导致的,比如 jdk, eclpise, idea, mysql,tomcat 等等软件的版本不一致。
请使用和站长一样的版本,可以节约自己大量的学习时间。 站长把教学中用的软件版本整理了,都统一放在了这里, 方便大家下载: http://how2j.cn/k/helloworld/helloworld-version/1718.html

上传截图