//1.页面布局
div style="padding: 0 0 20px 0;">
input type="hidden" class="tip" value="1">
input style="background:#01affe;color: #FFF;cursor: pointer;
text-align:center;height:30px;vertical-align: middle;padding:0 5px;
type="button" name="more" id="more" value="加载更多" onclick="moreData();"/>
/div>
//2.js代码
function moreData(){
var ptip = $('.tip').val();
var jstr = {pageNo:ptip};
$.ajax({
url: '${rc.getContextPath()}/publicity/more.do',//url以具体为实现
type: 'POST',
dataType: 'html',
data:jstr,
timeout: 5000,
cache: false,
beforeSend: LoadFunction, //加载执行方法
error: erryFunction, //错误执行方法
success: succFunction //成功执行方法
})
function LoadFunction() {
$("#more").val('加载中...');
}
function erryFunction() {
alert("获取数据错误,请重试!");
$("#more").val('加载更多');
}
function succFunction(data) {
if(data!=null data!=""){
$('.tip').val(++ptip);
$("#more").val('加载更多');
$('.mainContent').append(data);
}else{
$("#more").val('无更多数据');
$("#more").attr('disabled',true);
}
}
//3.后台代码
//3.1 java代码实现
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.appmoudle.base.Consts;
import com.appmoudle.model.ssdj.Publicity;
import com.appmoudle.service.PublicityService;
@Controller
@RequestMapping("/publicity")
public class MoreData {
private String ftlURL = ".../publicity/MoreData.ftl";
@Autowired
private PublicityService publicityService;
@RequestMapping(value="more",method=RequestMethod.POST)
public String getMoreData(HttpServletRequest request,ModelMap map){
Integer start = 0;
String pageNo = request.getParameter("pageNo");
if(pageNo!=null){
start = Integer.parseInt(pageNo) * 20;
}
ListPublicity> dataList = publicityService.findList(start, Consts.PAGE_SIZE, null, "1", null, null);
map.put("index_number", start);
map.put("dataList", dataList);
return ftlURL;
}
}
//3.2 模板页面
//(MoreData.ftl)
#if dataList??>
#list dataList as dataItem>
tr>
td class='f-blue'>${dataItem_index+1+index_number}/td>
td>
#if dataItem.comp_name?length gt; 12>
${dataItem.comp_name?substring(0,12)}..
#else>
${dataItem.comp_name}
/#if>
/td>
td>${dataItem.license_number}/td>
td>
#if dataItem.license_name?length gt; 10>
${dataItem.license_name?substring(0,10)}..
#else>
${dataItem.license_name}
/#if>
/td>
td>
#if dataItem.validaty_start?has_content>
${dataItem.validaty_start?date}
/#if>
/td>
td>
#if dataItem.validaty_end?has_content>
${dataItem.validaty_end?date}
/#if>
/td>
td>
#if dataItem.license_content?length gt; 20>
${dataItem.license_content?substring(0,20)}..
#else>
${dataItem.license_content}
/#if>
/td>
/tr>
/#list>
/#if>