微服务 教程
1085个小节阅读:195.9k
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
新增产品时需要选择产品类别,所以不能直接访问新增产品页面,需要在controller
中查询到所有产品类别,在跳转到新增页面。
在CategoryService
添加查询所有类别的方法
xxxxxxxxxx
public List<Category> findAll(){
return categoryMapper.selectList(null);
}
编写ProductSerive
xxxxxxxxxx
public void add(Product product){
productMapper.insert(product);
}
编写ProductController
xxxxxxxxxx
"/addPage") (
public ModelAndView addPage() {
// 查询所有产品类别
List<Category> categoryList = categoryService.findAll();
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("categoryList", categoryList);
modelAndView.setViewName("/backstage/product_add");
return modelAndView;
}
"/add") (
public String add(Product product) {
productService.add(product);
return "redirect:/backstage/product/all";
}
编写页面product_add.html
xxxxxxxxxx
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>新增旅游产品</title>
<th:block th:replace="/backstage/common_resources::common_css"></th:block>
<th:block th:replace="/backstage/common_resources::common_js"></th:block>
</head>
<body class="hold-transition skin-purple sidebar-mini">
<header th:replace="~{/backstage/common_header::header}"></header>
<aside th:replace="~{/backstage/common_aside::aside}"></aside>
<div class="wrapper">
<div class="content-wrapper">
<!-- 内容头部 -->
<section class="content-header">
<h1>
旅游产品管理
<small>新增旅游产品</small>
</h1>
<ol class="breadcrumb">
<li><a href="@{/backstage/index}"><i class="fa fa-dashboard"></i> 首页</a></li>
<li><a href="@{/backstage/product/all}">旅游产品管理</a></li>
<li class="active">新增旅游产品</li>
</ol>
</section>
<!-- 内容头部 /-->
<!-- 正文区域 -->
<section class="content">
<form th:action="@{/backstage/product/add}" method="post">
<div class="row data-type">
<div class="col-md-2 title">产品名称</div>
<div class="col-md-4 data">
<input type="text" class="form-control" placeholder="产品名称" name="productName">
</div>
<div class="col-md-2 title">产品类型</div>
<div class="col-md-4 data">
<select class="form-control" name="cid">
<option th:each="category:${categoryList}"
th:value="${category.cid}"
th:text="${category.cname}"></option>
</select>
</div>
<div class="col-md-2 title">价格</div>
<div class="col-md-4 data">
<input type="number" class="form-control" placeholder="价格" name="price">
</div>
<div class="col-md-2 title">热线电话</div>
<div class="col-md-4 data">
<input type="text" class="form-control" placeholder="热线电话" name="hotline" value="">
</div>
<div class="col-md-2 title">状态</div>
<div class="col-md-4 data">
<select class="form-control" name="status">
<option value="true">开启</option>
<option value="false">关闭</option>
</select>
</div>
<div class="col-md-6 data"></div>
<div class="col-md-2 title" style="height: 350px">产品详情</div>
<div class="col-md-10 data" style="height: 350px">
<textarea name="prodcutDesc" style="width: 100%;height: 100%"></textarea>
</div>
<div class="col-md-2 title"></div>
<div class="col-md-10 data text-center">
<button type="submit" class="btn bg-maroon">保存</button>
<button type="button" class="btn bg-default" onclick="history.back(-1);">返回</button>
</div>
</div>
</form>
</section>
<!-- 正文区域 /-->
</div>
</div>
<footer th:replace="~{/backstage/common_footer::footer}"></footer>
</body>
</html>
启动项目,测试方法