Commit 7493a709 authored by 杨伊博's avatar 杨伊博

add page limit

parent 5dbce86a
...@@ -62,6 +62,12 @@ ...@@ -62,6 +62,12 @@
</dependency> </dependency>
<!--util--> <!--util-->
<dependency>
<groupId>com.jf</groupId>
<artifactId>page-mysql</artifactId>
<version>1.0</version>
</dependency>
<dependency> <dependency>
<groupId>org.apache.commons</groupId> <groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId> <artifactId>commons-lang3</artifactId>
......
...@@ -9,7 +9,7 @@ import static org.springframework.boot.SpringApplication.*; ...@@ -9,7 +9,7 @@ import static org.springframework.boot.SpringApplication.*;
* Created by yangyibo on 17/1/17. * Created by yangyibo on 17/1/17.
*/ */
@ComponentScan(basePackages ="com.us.example") @ComponentScan(basePackages ="com.us.example,com.jf")
@SpringBootApplication @SpringBootApplication
@EnableScheduling @EnableScheduling
public class Application { public class Application {
......
package com.us.example.config; package com.us.example.config;
import javax.sql.DataSource; import javax.sql.DataSource;
import com.jf.page.interceptor.PageInterceptor;
import org.apache.ibatis.plugin.Interceptor;
import org.mybatis.spring.SqlSessionFactoryBean; import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
...@@ -19,6 +21,7 @@ public class MyBatisConfig { ...@@ -19,6 +21,7 @@ public class MyBatisConfig {
public SqlSessionFactoryBean sqlSessionFactory(ApplicationContext applicationContext) throws Exception { public SqlSessionFactoryBean sqlSessionFactory(ApplicationContext applicationContext) throws Exception {
SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean(); SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
sessionFactory.setDataSource(dataSource); sessionFactory.setDataSource(dataSource);
sessionFactory.setPlugins(new Interceptor[]{new PageInterceptor()});
sessionFactory.setMapperLocations(applicationContext.getResources("classpath*:mapper/*.xml")); sessionFactory.setMapperLocations(applicationContext.getResources("classpath*:mapper/*.xml"));
return sessionFactory; return sessionFactory;
} }
......
...@@ -32,7 +32,7 @@ public class UserController { ...@@ -32,7 +32,7 @@ public class UserController {
/*** /***
* api :localhost:8099/users?id=99 * api :localhost:8099/users?id=99
* * http://localhost:8099/users?limit=2&page=2
* @param request * @param request
* @return * @return
*/ */
......
...@@ -4,6 +4,7 @@ package com.us.example.service.Impl; ...@@ -4,6 +4,7 @@ package com.us.example.service.Impl;
import java.util.Date; import java.util.Date;
import java.util.Map; import java.util.Map;
import com.jf.page.annotation.Page;
import javafx.scene.input.DataFormat; import javafx.scene.input.DataFormat;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
...@@ -30,13 +31,15 @@ public class UserServiceImpl implements UserService { ...@@ -30,13 +31,15 @@ public class UserServiceImpl implements UserService {
* @param map * @param map
* @return * @return
*/ */
@Page
@Override
public Object getList(Map<String, Object> map) { public Object getList(Map<String, Object> map) {
printName();
return userDao.getList(map); return userDao.getList(map);
} }
//每一秒调用一次 -- 用于测试 //每一秒调用一次 -- 用于测试
@Scheduled(cron = "0/30 * * * * ?") @Scheduled(cron = "0/30 * * * * ?")
@Override
public void printName() { public void printName() {
System.out.println(new Date()); System.out.println(new Date());
System.out.println("my name is yang "); System.out.println("my name is yang ");
......
...@@ -17,5 +17,6 @@ public interface UserService { ...@@ -17,5 +17,6 @@ public interface UserService {
*/ */
Object getList(Map<String, Object> map); Object getList(Map<String, Object> map);
void printName();
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment