BillController.java
张创琦
package com.zcq.controller;import com.github.pagehelper.PageInfo;import com.zcq.entity.Bill;import com.zcq.entity.BillType;import com.zcq.service.BillService;import com.zcq.service.TypeService;import org.springframework.stereotype.Controller;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.PathVariable;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestParam;import javax.annotation.Resource;import java.util.List;@Controller@RequestMapping("/bill")public class BillController {@Resourceprivate TypeService typeService;@Resourceprivate BillService billService;@RequestMapping("/list-page")public String listPage(@RequestParam(defaultValue = "1") int pageNum,@RequestParam(defaultValue = "10") int pageSize,Bill b, Model model) {List<BillType> types = typeService.list();model.addAttribute("types", types);PageInfo<Bill> pageInfo = billService.listPage(b, pageNum, pageSize);model.addAttribute("page", pageInfo);model.addAttribute("bill", b);return "/bill/list-page";}// 查询@RequestMapping("/list")public String list(Bill b, Model model) {List<BillType> types = typeService.list();model.addAttribute("types", types);List<Bill> list = billService.list(b);model.addAttribute("list", list);model.addAttribute("bill", b);return "/bill/list";}// 调到添加页面// 经测试,无法添加数据@RequestMapping("/toAdd")public String toAdd(Model model) {List<BillType> types = typeService.list();model.addAttribute("types", types);return "/bill/add";}// 添加@RequestMapping("/add")public String add(Bill b) {billService.add(b);return "redirect:/bill/list";}// 删除// 可以通过指令删除, 但是无法通过list的点击按钮进行@RequestMapping("/delete/{id}")public String delete(@PathVariable("id") Long id) {billService.delete(id);return "redirect:/bill/list";}// 修改@RequestMapping("/toUpdate/{id}")public String toUpdate(@PathVariable("id") Long id, Model model) {List<BillType> types = typeService.list();model.addAttribute("types", types);Bill bill = billService.get(id);model.addAttribute("bill", bill);return "/bill/update";}// 修改@RequestMapping("/update")public String update(Bill b) {billService.update(b);return "redirect:/bill/list";}}
