首页>代码>mybatis-spring-pagehelper分页实现和模糊查找例子>/mybatis-spring-pagehelper/src/main/java/com/isea533/mybatis/controller/demo/CountryController.java
package com.isea533.mybatis.controller.demo;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;
import com.isea533.mybatis.model.Country;
import com.isea533.mybatis.service.CountryService;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @author liuzh_3nofxnp
 * @since 2015-09-19 17:15
 */
@Controller
public class CountryController {

	public static Logger logger = Logger.getLogger(CountryController.class);
    @Autowired
    private CountryService countryService;

    private String page_list = "index";

    private String redirect_list = "redirect:list";

    @RequestMapping(value = {"list", "index", "index.html", ""})
    public ModelAndView getList(Country country,
                                @RequestParam(required = false, defaultValue = "1") int page,
                                @RequestParam(required = false, defaultValue = "10") int rows) {
        ModelAndView result = new ModelAndView(page_list);
        List<Country> countryList = countryService.selectByCountry(country, page, rows);
        result.addObject("pageInfo", new PageInfo<Country>(countryList));
        result.addObject("queryParam", country);
        result.addObject("page", page);
        result.addObject("rows", rows);
        
       logger.info("------"+JSON.toJSONString(new PageInfo<Country>(countryList)));
        
        return result;
    }

    @RequestMapping(value = "view", method = RequestMethod.GET)
    public ModelAndView view(Country country) {
        ModelAndView result = new ModelAndView();
        if (country.getId() != null) {
            country = countryService.selectByKey(country.getId());
        }
        result.addObject("country", country);
        return result;
    }

    @RequestMapping(value = "save", method = RequestMethod.POST)
    public ModelAndView save(Country country) {
        ModelAndView result = new ModelAndView(redirect_list);
        if (country.getId() != null) {
            countryService.updateAll(country);
        } else {
            countryService.save(country);
        }
        return result;
    }

    @RequestMapping("delete")
    public String delete(Integer id) {
        countryService.delete(id);
        return redirect_list;
    }

}
最近下载更多
2875754292  LV3 2021年6月23日
luowu11111  LV3 2021年4月28日
zhoujunyu  LV14 2021年4月1日
andy xiao2222222  LV9 2021年3月19日
solider12  LV8 2021年1月12日
zxc2mm1414  LV11 2020年12月19日
hjd3983  LV10 2020年12月10日
yale1422688399  LV3 2020年11月16日
qq278246140  LV12 2020年9月19日
aqsx1598  LV7 2020年8月19日
最近浏览更多
微信网友_6802139027345408  LV2 2023年12月31日
李亮  LV19 2023年3月6日
shufsjnjksf  LV1 2022年10月25日
呵呵哈哈哈  LV10 2022年9月3日
sgwtfdtvd  LV1 2022年6月8日
cab123123  LV8 2022年4月15日
CCG542517  LV6 2022年3月28日
fengshengtian  LV8 2022年2月28日
leonard0810  LV1 2022年2月13日
lyws1986  LV17 2021年12月21日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友