俺们这些个敲代码的民工们有福了,Google推出了源代码搜索功能,顾名思义就是搜索网上大量的开源代码,以后不用再费劲叭啦的奔波于各大开源网站、论坛(还不一定找到)了,google一下吧,而且还支持正则表达式。
下面的就是我用这个功能搜索到的google自已的分页代码。
/**
* Copyright 2009 Adam Ruggles.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.code.sapien.action;
import java.util.List;
import com.google.code.sapien.model.Category;
import com.google.code.sapien.model.Discussion;
import com.google.code.sapien.service.CategoryService;
import com.google.code.sapien.service.DiscussionService;
import com.google.code.sapien.util.PaginatedResult;
import com.google.inject.Inject;
import com.opensymphony.xwork2.ActionSupport;
/**
* Index Action, controls the view of the main index page.
* @author Adam
* @version $Id$
*
* Created on Feb 18, 2009 at 10:08:16 PM
*/
public class IndexAction extends ActionSupport {
/**
* The default number of results per page.
*/
public static final int RESULTS_PER_PAGE = 50;
/**
* Serial Version UID.
*/
private static final long serialVersionUID = -2980491615589545156L;
/**
* A List of categories for displaying in the view.
*/
private List<Category> categories;
/**
* The category service.
*/
private final CategoryService categoryService;
/**
* The discussion service.
*/
private final DiscussionService discussionService;
/**
* The page number.
*/
private int page = 1;
/**
* A PaginatedResult of discussions.
*/
private PaginatedResult<Discussion> paginatedResult;
/**
* Constructs a index action.
* @param discussionService The discussion service.
* @param categoryService The categoryService.
*/
@Inject
public IndexAction(final DiscussionService discussionService, final CategoryService categoryService) {
super();
this.discussionService = discussionService;
this.categoryService = categoryService;
}
/**
*
* {@inheritDoc}
* @see com.opensymphony.xwork2.ActionSupport#execute()
*/
@Override
public String execute() {
paginatedResult = discussionService.getModifiedDesc(page, RESULTS_PER_PAGE);
categories = categoryService.getAll();
return SUCCESS;
}
/**
* Returns categories.
* @return the categories.
*/
public List<Category> getCategories() {
return categories;
}
/**
* Returns page.
* @return the page.
*/
public int getPage() {
return page;
}
/**
* Returns paginatedResult.
* @return the paginatedResult.
*/
public PaginatedResult<Discussion> getPaginatedResult() {
return paginatedResult;
}
/**
* Sets page.
* @param page the page to set.
*/
public void setPage(final int page) {
if (page <= 0) {
this.page = 1;
} else {
this.page = page;
}
}
}
快去体验一下吧!
哈哈,欢呼吧同胞们....