JAVA全系列 教程
3762个小节阅读:7095k
目录
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
接下来我们对旅游产品进行管理,不同的旅游产品有不同类型,我们首先对类型进行管理,接下来我们编写产品分类管理的后端代码:
编写CategoryMapper
xxxxxxxxxx
public interface CategoryMapper extends BaseMapper<Category> {
}
编写CategoryService
xxxxxxxxxx
@Service
public class CategoryService {
@Autowired
private CategoryMapper categoryMapper;
public Page<Category> findPage(int page, int size){
return categoryMapper.selectPage(new Page(page,size),null);
}
public void add(Category category){
categoryMapper.insert(category);
}
public Category findById(Integer cid){
return categoryMapper.selectById(cid);
}
public void update(Category category){
categoryMapper.updateById(category);
}
public void delete(Integer cid){
categoryMapper.deleteById(cid);
}
}
编写CategoryController
xxxxxxxxxx
@Controller
@RequestMapping("/backstage/category")
public class CategoryController {
@Autowired
private CategoryService categoryService;
@RequestMapping("/all")
public ModelAndView all(@RequestParam(defaultValue = "1") int page,
@RequestParam(defaultValue = "10")int size){
Page<Category> categoryPage = categoryService.findPage(page, size);
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("categoryPage",categoryPage);
modelAndView.setViewName("/backstage/category_all");
return modelAndView;
}
@RequestMapping("/add")
public String add(Category category){
categoryService.add(category);
return "redirect:/backstage/category/all";
}
@RequestMapping("/edit")
public ModelAndView edit(Integer cid){
Category category = categoryService.findById(cid);
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("category",category);
modelAndView.setViewName("/backstage/category_edit");
return modelAndView;
}
@RequestMapping("/update")
public String update(Category category){
categoryService.update(category);
return "redirect:/backstage/category/all";
}
@RequestMapping("/delete")
public String delete(Integer cid){
categoryService.delete(cid);
return "redirect:/backstage/category/all";
}
}