Spring Boot实践应用开发(11)


【显示信息】

 

准备,下载eighth.zip并导入到eclipse,下载地址http://pan.baidu.com/s/1c2GaAFA。

同时,请导入Limy插件,Limy(eclipse_plugin).zip。下载完成后解压到eclipse的dropins目录下即可以使用。下载地址http://pan.baidu.com/s/1o6spOJS。(eclipse_plugins\Limy(eclipse_plugin).zip)

 

1,新规messages.properties(请使用Limy编辑)

 

I0000001=没有检索到结果。

 

2,修改users.html





Users






	

Users

用户名

检索结果 << <  / > >>

No. username password rolename

检索结果 << <  / > >>


 

3,修改UsersController.java

package org.com.sample.controller;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

import org.com.common.paging.PagenationHelper;
import org.com.sample.dataset.Users;
import org.com.sample.facade.UsersFacade;
import org.com.sample.form.UsersInputForm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("/sample/users")
public class UsersController {

	private static final Logger logger = LoggerFactory.getLogger(UsersController.class);

	private static final int DEFAULT_PAGEABLE_SIZE = 10;

	@Autowired
	UsersFacade usersFacade;

	@Autowired
	MessageSource messageSource;

	@RequestMapping(value = "/show", method = { RequestMethod.GET, RequestMethod.POST })
	public String selectAllUser(@PageableDefault(page = 0, size = DEFAULT_PAGEABLE_SIZE) Pageable pageable,
			Model model) {

		// List userList = usersFacade.selectByExample(new
		// UsersExample());

		Map map = new HashMap();
		map.put("start_line", pageable.getOffset() + 1);
		map.put("end_line", (pageable.getPageNumber() + 1) * pageable.getPageSize());
		map.put("orderByClause", "username asc");
		map.put("form", new UsersInputForm());

		Page page = usersFacade.selectUserListForPaging(map, pageable);
		PagenationHelper ph = null;
		if (page != null) {
			ph = new PagenationHelper(page.getNumber(), page.getSize(), page.getTotalPages());
		} else {
			model.addAttribute("sysMsg", messageSource.getMessage("I0000001", null, Locale.getDefault()));
		}

		model.addAttribute("page", page);
		model.addAttribute("ph", ph);

		return "sample/users/users";
	}

	@RequestMapping(value = "/doSearch", method = { RequestMethod.GET, RequestMethod.POST })
	public String doSearch(UsersInputForm form, BindingResult result,
			@PageableDefault(page = 0, size = DEFAULT_PAGEABLE_SIZE) Pageable pageable, Model model) {

		Map map = new HashMap();
		map.put("start_line", pageable.getOffset() + 1);
		map.put("end_line", (pageable.getPageNumber() + 1) * pageable.getPageSize());
		map.put("orderByClause", "username asc");
		map.put("form", form);

		Page page = usersFacade.selectUserListForPaging(map, pageable);
		PagenationHelper ph = null;

		if (page != null) {
			ph = new PagenationHelper(page.getNumber(), page.getSize(), page.getTotalPages());
		} else {
			model.addAttribute("sysMsg", messageSource.getMessage("I0000001", null, Locale.getDefault()));
		}

		model.addAttribute("page", page);
		model.addAttribute("ph", ph);

		return "sample/users/users";
	}

	@ModelAttribute
	public UsersInputForm getUsersInputForm() {
		return new UsersInputForm();
	}

}

4, 启动项目,输入URL,http://localhost:8888/sample/users/show

       输入检索条件进行检索。

Spring Boot实践应用开发(11)_第1张图片 


代码下载地址

http://pan.baidu.com/s/1c2GaAFA,ninth.zip

你可能感兴趣的:(SPRING)