package ${packageName}.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
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 ${packageName}.model.${ClassName};
import ${packageName}.service.${ClassName}Service;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * ${functionName}Controller
 *
 * @author ${author}
 * @date ${datetime}
 */
@Controller
@RequestMapping("/${className}")
public class ${ClassName}Controller extends BaseController{
    @Autowired
    private ${ClassName}Service ${className}Service;

    /**
    * 分页列表
    */
    @RequestMapping(value = "/list")
    public String list(${ClassName} ${className},Integer curPage, Integer pageSize, ModelMap model, HttpServletRequest request){
        PageInfo<${ClassName}> pageInfo = ${className}Service.queryPage(${className}, pageNum(curPage), pageSize(request, pageSize));
        model.put("pages", pageInfo);
        model.put("${className}", ${className});
        return "/${className}_list";
    }

    /**
    * 新增页面
    */
    @RequestMapping(value = "/add", method = RequestMethod.GET)
    public String add(ModelMap model){
        return "/${className}_add";
    }

    /**
    * 新增
    */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public String add(${ClassName} ${className}, HttpServletRequest request, ModelMap model){
        ${className}Service.insert(${className});
        model.put("flag", true);
        return "/${className}_add";
    }

    /**
    * 修改页面
    */
    @RequestMapping(value = "/update", method = RequestMethod.GET)
    public String update(${ClassName} ${className}, ModelMap model){
        ${className} = ${className}Service.selectByPrimaryKey(${className}.get${pkColumn.javaField}());
        model.put("${className}", ${className});
        return "/${className}_edit";
    }

    /**
    * 修改
    */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public String update(${ClassName} ${className}, HttpServletRequest request,ModelMap model){
            ${className}Service.update(${className});
        model.put("flag", true);
        return "/${className}_edit";
    }

    /**
    * 明细页面
    */
    @RequestMapping(value = "/detail", method = RequestMethod.GET)
    public String detail(${ClassName} ${className}, ModelMap model){
        ${className} = ${className}Service.selectByPrimaryKey(${className}.get${pkColumn.javaField}());
        model.put("${className}", ${className});
        return "/${className}_detail";
    }

    /**
    * 删除
    */
    @RequestMapping(value = "/delete", method = RequestMethod.GET)
    @ResponseBody
    public void delete(${ClassName} ${className}){
        ${className}Service.deleteByPrimaryKey(${className}.get${pkColumn.javaField}());
    }
}
