对Spring MVC问题的分页

时间:2014-12-19 23:27:10

标签: java spring spring-mvc pagination

我在Spring MVC Restful Project工作,我想实现分页,所以我有这个控制器

控制器

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;

//HERE IMPORT PAGEABLE
import org.springframework.data.domain.Pageable;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;

import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.util.UriComponentsBuilder;

import edu.ucla.siged.dao.DaoJuegoI;
import edu.ucla.siged.domain.gestiondeportiva.Juego;


@Controller
@RequestMapping(value="/juegos")
public class ServicioJuegoRest {

    @Autowired
    private DaoJuegoI iJuego;


    @RequestMapping(value="/todos")
    public @ResponseBody Page todos(Pageable page){

        return iJuego.findAll(page);

    }

应用context.xml中

<?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:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jpa="http://www.springframework.org/schema/data/jpa"
    xmlns:oxm="http://www.springframework.org/schema/oxm" xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd">


    <aop:config proxy-target-class="true"/>
    <!-- Escanea el paquete base para hacer inyeccion segun las anotaciones -->
    <context:annotation-config />       
    <context:component-scan base-package="edu.ucla.siged" />

    <!-- se le indica donde estan las clases que usan JPA -->
    <jpa:repositories base-package="edu.ucla.siged.dao" />



    <bean id="mySessionFactory"  
    class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">  
    <property name="dataSource" ref="dataSource" />  
    <property name="packagesToScan">  
        <array>  
            <value>edu.ucla.siged</value>  
        </array>  
    </property>  
    <property name="hibernateProperties">  
        <props>  
            <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>  
        </props>  
    </property>  
    </bean>



    <context:annotation-config />
    <tx:annotation-driven transaction-manager="transactionManager" />

    <bean id="entityManagerFactory"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="persistenceUnitName" value="persistencia" /><!-- Ojo -->
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="generateDdl" value="true" />
                <property name="database" value="POSTGRESQL" />

            </bean>
        </property>
        <property name="jpaProperties">
            <props>

                <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
                <prop key="hibernate.format_sql">false</prop>
                <prop key="hibernate.show_sql">false</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop><!-- Ojo -->
            </props>
        </property>
    </bean>

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>
    <!-- Para las anotaciones Transacional -->  
    <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
        <property name="dataSource" ref="dataSource"></property>
    </bean>

    <bean class="org.springframework.orm.hibernate4.HibernateExceptionTranslator" />

    <!-- Rafa 10/12/2014 -->
    <!-- Se usa para procesar los multipart file usados en los rest service que reciben archivos en el request -->
    <bean id="multipartResolver"
    class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
     <!-- one of the properties available; the maximum file size in bytes -->
    <property name="maxUploadSize" value="200000"/>
    </bean>


</beans>

当我向Web服务发出请求时,我收到此错误..

请求处理失败;嵌套异常是org.springframework.beans.BeanInstantiationException:无法实例化bean类[org.springframework.data.domain.Pageable]:指定的类是一个接口

有人可以帮我这个吗?

提前致谢!

0 个答案:

没有答案