controller的部分:
@Controller
@RequestMapping("/ContactsFrameIndex")
public class ContactsFrameControl {
@Resource
private ContactsFrameServiceImpl contactsFrameServiceImpl;
/**
* 主界面
*
*/
@RequestMapping("/index")
public String getAllContactsList(HttpServletRequest request ,HttpServletResponse response,Model model,String page1){
int pageSize = 3;
//记录总条数;
int total = contactsFrameServiceImpl.total();
System.out.println(total);
if((total % pageSize)==0){
int totalPage = total/pageSize;
model.addAttribute("totalPage",totalPage);
}else{
int totalPage = total/pageSize +1;
model.addAttribute("totalPage",totalPage);
}
if(page1 == null || page1.equals("")){
int page = 1;
model.addAttribute("page1",page);
ListPage<ContactsFrameEntity> contactsList = contactsFrameServiceImpl.getAllContacts(page,pageSize);
model.addAttribute("contactsList",contactsList);
model.addAttribute("forwardUrl", RequestUtil.encodeUrl(request));
return "views/contacts/index";
}else{
int page = Integer.valueOf(page1);
if(page-1<=0){
page =1;
}
model.addAttribute("page1",page);
ListPage<ContactsFrameEntity> contactsList = contactsFrameServiceImpl.getAllContacts(page,pageSize);
model.addAttribute("contactsList",contactsList);
model.addAttribute("forwardUrl", RequestUtil.encodeUrl(request));
return "views/contacts/index";
}
index.ftl
例如做加减运算的语句是这样的:<a style="padding:0px 200px 10px 200px;"href="/ContactsFrameIndex/index.do?page1=${page1-1}" >上页</a> <a>当前第 ${page1} 页</a> <a style="padding-left:200px;"href="/ContactsFrameIndex/index.do?page1=${page1+1}">下页</a> <a style="padding:0px 200px 10px 200px;">总共${totalPage}页</a>
总之:freemarker:运算要在自己内部;
在此可以看出,controller中传入是int,ftl接收也是int,该是什么还是什么(框架这里已经帮我们全部转好了),所有在本文绿色部分有些这个可以直接用Integer接收,不需要用String;(我也懒得改了)