在ssm_parent工程上右键-new-module
还是无骨架maven
ssm_dao_331
同上,名字不同而已
在ssm_parent工程上右键-new-module
还是无骨架maven
ssm_service_331
注意手动加层目录
在ssm_parent工程上右键-new-module
选择maven-webapp骨架
ssm_web_331
手动加一级目录
在ssm_parent工程上右键-new-module
无骨架maven
ssm_domain_331
在ssm_parent工程上右键-new-module
无骨架maven
ssm_utils_331
<properties>
<project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
<maven.compiler.source>1.8maven.compiler.source>
<maven.compiler.target>1.8maven.compiler.target>
<spring.version>5.0.2.RELEASEspring.version>
<spring.security.version>5.0.2.RELEASEspring.security.version>
properties>
<dependencies>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-contextartifactId>
<version>${spring.version}version>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-txartifactId>
<version>${spring.version}version>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-jdbcartifactId>
<version>${spring.version}version>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-testartifactId>
<version>${spring.version}version>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-webmvcartifactId>
<version>${spring.version}version>
dependency>
<dependency>
<groupId>org.mybatisgroupId>
<artifactId>mybatisartifactId>
<version>3.4.5version>
dependency>
<dependency>
<groupId>org.mybatisgroupId>
<artifactId>mybatis-springartifactId>
<version>1.3.1version>
dependency>
<dependency>
<groupId>org.aspectjgroupId>
<artifactId>aspectjweaverartifactId>
<version>1.8.7version>
dependency>
<dependency>
<groupId>com.alibabagroupId>
<artifactId>druidartifactId>
<version>1.1.9version>
dependency>
<dependency>
<groupId>junitgroupId>
<artifactId>junitartifactId>
<version>4.12version>
<scope>testscope>
dependency>
<dependency>
<groupId>javax.servletgroupId>
<artifactId>jsp-apiartifactId>
<version>2.0version>
<scope>providedscope>
dependency>
<dependency>
<groupId>javax.servletgroupId>
<artifactId>servlet-apiartifactId>
<version>2.5version>
<scope>providedscope>
dependency>
<dependency>
<groupId>log4jgroupId>
<artifactId>log4jartifactId>
<version>1.2.17version>
dependency>
<dependency>
<groupId>org.apache.logging.log4jgroupId>
<artifactId>log4j-apiartifactId>
<version>2.10.0version>
dependency>
<dependency>
<groupId>org.apache.logging.log4jgroupId>
<artifactId>log4j-coreartifactId>
<version>2.10.0version>
dependency>
<dependency>
<groupId>org.apache.logging.log4jgroupId>
<artifactId>log4j-webartifactId>
<version>2.9.1version>
dependency>
<dependency>
<groupId>org.slf4jgroupId>
<artifactId>slf4j-apiartifactId>
<version>1.7.25version>
dependency>
<dependency>
<groupId>org.apache.logging.log4jgroupId>
<artifactId>log4j-slf4j-implartifactId>
<version>2.9.1version>
dependency>
<dependency>
<groupId>org.apache.logging.log4jgroupId>
<artifactId>log4j-jclartifactId>
<version>2.9.1version>
dependency>
<dependency>
<groupId>mysqlgroupId>
<artifactId>mysql-connector-javaartifactId>
<version>5.1.6version>
dependency>
<dependency>
<groupId>com.oraclegroupId>
<artifactId>ojdbc14artifactId>
<version>10.2.0.3.0version>
dependency>
<dependency>
<groupId>jstlgroupId>
<artifactId>jstlartifactId>
<version>1.2version>
dependency>
<dependency>
<groupId>taglibsgroupId>
<artifactId>standardartifactId>
<version>1.1.1version>
dependency>
<dependency>
<groupId>commons-fileuploadgroupId>
<artifactId>commons-fileuploadartifactId>
<version>1.3.1version>
dependency>
<dependency>
<groupId>commons-iogroupId>
<artifactId>commons-ioartifactId>
<version>2.5version>
dependency>
<dependency>
<groupId>c3p0groupId>
<artifactId>c3p0artifactId>
<version>0.9.1.2version>
dependency>
<dependency>
<groupId>com.github.pagehelpergroupId>
<artifactId>pagehelperartifactId>
<version>5.1.2version>
dependency>
<dependency>
<groupId>org.springframework.securitygroupId>
<artifactId>spring-security-webartifactId>
<version>${spring.security.version}version>
dependency>
<dependency>
<groupId>org.springframework.securitygroupId>
<artifactId>spring-security-configartifactId>
<version>${spring.security.version}version>
dependency>
<dependency>
<groupId>org.springframework.securitygroupId>
<artifactId>spring-security-coreartifactId>
<version>${spring.security.version}version>
dependency>
<dependency>
<groupId>org.springframework.securitygroupId>
<artifactId>spring-security-taglibsartifactId>
<version>${spring.security.version}version>
dependency>
dependencies>
ojdbc14:10.2.0.2.0 版本总是报波浪线 改成0.2.0.3.0 即可
可能是本地仓库的xml配置原因:
复制到webapp目录下即可
jdbc.driver=oracle.jdbc.driver.OracleDriver
jdbc.url=jdbc:oracle:thin:@localhost:1521:orcl
jdbc.username=ssm331
jdbc.password=123
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:property-placeholder location="classpath:jdbc.properties">context:property-placeholder>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driver}">property>
<property name="url" value="${jdbc.url}">property>
<property name="username" value="${jdbc.username}">property>
<property name="password" value="${jdbc.password}">property>
bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource">property>
bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="cn.ahpu.dao">property>
bean>
beans>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
<context:component-scan base-package="cn.ahpu.service">context:component-scan>
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource">property>
bean>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="query*" read-only="true" propagation="SUPPORTS"/>
<tx:method name="get*" read-only="true" propagation="SUPPORTS"/>
<tx:method name="find*" read-only="true" propagation="SUPPORTS"/>
<tx:method name="*" read-only="false" propagation="REQUIRED"/>
tx:attributes>
tx:advice>
<aop:config>
<aop:advisor advice-ref="txAdvice" pointcut="execution(* cn.ahpu.service.impl.*.*(..))">aop:advisor>
aop:config>
beans>
先将页面复制到webapp目录下
再创建包结构
写spring-mvc.xml和web.xml
注:此处resources目录没有spring目录了 spring-mvc.xml就在resources根目录下,本来就不是spring核心配置文件嘛
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:component-scan base-package="cn.ahpu.controller">context:component-scan>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/pages/">property>
<property name="suffix" value=".jsp">property>
bean>
<mvc:annotation-driven>mvc:annotation-driven>
<mvc:default-servlet-handler>mvc:default-servlet-handler>
beans>
<web-app>
<display-name>Archetype Created Web Applicationdisplay-name>
<context-param>
<param-name>contextConfigLocationparam-name>
<param-value>classpath*:spring/*.xmlparam-value>
context-param>
<filter>
<filter-name>CharacterEncodingFilterfilter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilterfilter-class>
<init-param>
<param-name>encodingparam-name>
<param-value>utf-8param-value>
init-param>
filter>
<filter-mapping>
<filter-name>CharacterEncodingFilterfilter-name>
<url-pattern>/*url-pattern>
filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListenerlistener-class>
listener>
<servlet>
<servlet-name>DispatcherServletservlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class>
<init-param>
<param-name>contextConfigLocationparam-name>
<param-value>classpath:spring-mvc.xmlparam-value>
init-param>
servlet>
<servlet-mapping>
<servlet-name>DispatcherServletservlet-name>
<url-pattern>/url-pattern>
servlet-mapping>
web-app>
create sequence product_seq; -- oracle每创建一张表就创建一个序列
CREATE TABLE product(
id number PRIMARY KEY ,
productNum VARCHAR2(50) NOT NULL UNIQUE,
productName VARCHAR2(50),
cityName VARCHAR2(50),
departureTime date,
productPrice number(8,2),
productDesc VARCHAR2(500),
productStatus INT
)
其中字段描述如下:
序号 | 字段名称 | 字段类型 | 字段描述 |
---|---|---|---|
1 | id | number | 无意义 |
2 | productNum | varchar2(50) | 产品编号,唯一,不为空 |
3 | productName | varchar2(50) | 产品名称(路线名称) |
4 | cityName | varchar2(50) | 出发城市 |
5 | departureTime | date | 出发时间 |
6 | productPrice | number(8,2) | 产品价格 |
7 | productDesc | varchar2(500) | 产品描述 |
8 | productStatus | int | 状态(0 关闭 1 开启) |
ssm_domain_331内引入lombok
@Data
public class Product {
private Integer id;
private String productNum;
private String productName;
private String cityName;
private Date departureTime;
private Double productPrice;
private String productDesc;
private Integer productStatus;
}
先写controller 有错误留着 慢慢写 等错误全没了也就写好了 这样不容易忘记东西
ProductController
@Controller
@RequestMapping("/product")
public class ProductController {
@Autowired
ProductService productService;
@RequestMapping("/findAll")
public ModelAndView findAll(){
ModelAndView modelAndView = new ModelAndView();
//数据
List<Product> products = productService.findAll();
System.out.println("产品:"+products);
modelAndView.addObject("products",products);
//页面
modelAndView.setViewName("product-list");
//返回
return modelAndView;
}
}
ProductService接口
public interface ProductService {
List<Product> findAll();
}
ProductServiceImpl接口实现
@Service
public class ProductServiceImpl implements ProductService {
@Autowired
ProductDao productDao;
@Override
public List<Product> findAll() {
return productDao.findAll();
}
}
ProductDao
public interface OrderDao {
@Select("select * from orders")
/*一对一级联查询*/
@Results({
@Result(property = "product" ,column = "productId",javaType = Product.class,
one = @One(select = "cn.ahpu.dao.ProductDao.findById"))
})
List<Order> findAll();
}
引入格式化标签库 用来处理日期格式非常方便
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<table id="dataList"
class="table table-bordered table-striped table-hover dataTable">
<thead>
<tr>
<th class="" style="padding-right: 0px;"><input
id="selall" type="checkbox" class="icheckbox_square-blue">
th>
<th class="sorting_asc">IDth>
<th class="sorting">产品编号th>
<th class="sorting">产品名称th>
<th class="sorting">出发城市th>
<th class="sorting">出发时间th>
<th class="sorting">产品价格th>
<th class="sorting">产品描述th>
<th class="sorting">产品状态th>
<th class="text-center">操作th>
tr>
thead>
<tbody>
<c:forEach items="${products}" var="product">
<tr>
<td><input name="ids" type="checkbox">td>
<td>${product.id}td>
<td>${product.productNum}td>
<td>${product.productName}td>
<td>${product.cityName}td>
<td>
<%--el标签可以 格式化标签 注意MM大写--%>
<fmt:formatDate value="${product.departureTime}" pattern="yyyy-MM-dd">fmt:formatDate>
td>
<td>${product.productPrice}td>
<td>${product.productDesc}td>
<td>${product.productStatus == 1?'开启':'关闭'}td>
<td class="text-center">
<button type="button" class="btn bg-olive btn-xs"
onclick='location.href="all-order-manage-edit.html"'>删除button>
<button type="button" class="btn bg-olive btn-xs"
onclick='location.href="all-order-manage-edit.html"'>修改button>
td>
tr>
c:forEach>
tbody>
table>
@RequestMapping("/save")
public String save(Product product){
productService.save(product);
return "redirect:/product/findAll";//防止别的模块内也有findAll方法 写绝对路径
}
public interface ProductService {
List<Product> findAll();
void save(Product product);
}
@Override
public void save(Product product) {
productDao.save(product);
}
@Insert("insert into product values(product_seq.nextval,#{productNum},#{productName}," +
"#{cityName},#{departureTime},#{productPrice},#{productDesc},#{productStatus})")
void save(Product product);
也可以这么写sql 先查询下主键 直接就到了Product里 然后再去插入
StringToDateConverter
public class StringToDateConverter implements Converter<String,Date> {
@Override
public Date convert(String source) {
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm");
try {
Date date = sdf.parse(source);
return date;
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
}
spring-mvc.xml
<!--扫描包:创建web层对象-->
<context:component-scan base-package="cn.ahpu.controller"></context:component-scan>
<!--创建类型转换器 工厂类对象 前端:string->Controller:date
写完 上面的注解驱动别忘记引用
-->
<bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean">
<property name="converters">
<set>
<bean class="cn.ahpu.converter.StringToDateConverter"></bean>
</set>
</property>
</bean>
@RequestMapping("/updateUI")
public ModelAndView updateUI(Integer productId){
ModelAndView modelAndView = new ModelAndView();
System.out.println(productId);
Product product=productService.findById(productId);
System.out.println(product);
modelAndView.addObject("product",product);
modelAndView.setViewName("product-update");
return modelAndView;
}
void update(Product product);
ProductServiceImpl实现
@Override
public Product findById(Integer id) {
return productDao.findById(id);
}
@Select("select * from product where id = #{id}")
Product findById(Integer id);
<form action="${pageContext.request.contextPath}/product/update"
method="post">
<input type="hidden" name="id" value="${product.id}">
<section class="content">
<div class="panel panel-default">
<div class="panel-heading">产品信息div>
<div class="row data-type">
<div class="col-md-2 title">产品编号div>
<div class="col-md-4 data">
<input type="text" class="form-control" name="productNum"
placeholder="产品编号" value="${product.productNum}"
readonly="readonly">
div>
<div class="col-md-2 title">产品名称div>
<div class="col-md-4 data">
<input type="text" class="form-control" name="productName"
placeholder="产品名称" value="${product.productName}">
div>
<div class="col-md-2 title">出发时间div>
<div class="col-md-4 data">
<div class="input-group date">
<div class="input-group-addon">
<i class="fa fa-calendar">i>
div>
<input type="text" class="form-control pull-right"
id="datepicker-a3" name="departureTime"
value="${product.departureTimeStr}">
div>
div>
<div class="col-md-2 title">出发城市div>
<div class="col-md-4 data">
<input type="text" class="form-control" name="cityName"
placeholder="出发城市" value="${product.cityName}">
div>
<div class="col-md-2 title">产品价格div>
<div class="col-md-4 data">
<input type="text" class="form-control" placeholder="产品价格"
name="productPrice" value="${product.productPrice}">
div>
<div class="col-md-2 title">产品状态div>
<div class="col-md-4 data">
<select id="productStatus" class="form-control select2" style="width: 100%"
name="productStatus">
<%--<option value="0" if test="${product.productStatus == 0}">selected="selected"c:if> >关闭option>
<option value="1" if test="${product.productStatus == 1}">selected="selected"c:if> >开启option>--%>
<%-- 用jquery写最方便 --%>
<option value="0" >关闭option>
<option value="1" >开启option>
select>
div>
<div class="col-md-2 title rowHeight2x">其他信息div>
<div class="col-md-10 data rowHeight2x">
<textarea class="form-control" rows="3" placeholder="其他信息"
name="productDesc">${product.productDesc}textarea>
div>
div>
div>
<div class="box-tools text-center">
<button type="submit" class="btn bg-maroon">修改button>
<button type="button" class="btn bg-default"
onclick="history.back(-1);">返回button>
div>
section>
form>
<script
src="${pageContext.request.contextPath}/plugins/jQuery/jquery-2.2.3.min.js">script>
<script
src="${pageContext.request.contextPath}/plugins/jQueryUI/jquery-ui.min.js">script>
<script>
$.widget.bridge('uibutton', $.ui.button);
//千万注意编码位置 引入的jquery之下
//修改界面 selected option的默认选项
$("#productStatus option[value=${product.productStatus}]").prop("selected","selected");
script>
页面入口value=“字符串内无法写el表达式 于是乎最简单的方法 直接在javaBean内多加一个get方法即可”
sql语句查询多自定义一个查询列 然后取个别名也行
value="${product.departureTimeStr}"
@Data
public class Product {
//...
private Date departureTime;
private String departureTimeStr;//方便前端显示 所以说直接写成string多好 前端提交的都是string
//...
public String getDepartureTimeStr() {
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm");
String timeStr = sdf.format(departureTime);
return timeStr;
}
}
数据库改成timestamp类型,否则时间查不到
@RequestMapping("/update")
public String update(Product product){
System.out.println(product);
productService.update(product);
return "redirect:/product/findAll";
}
ProductService接口
void update(Product product);
ProductServiceImpl实现
@Override
public void update(Product product) {
productDao.update(product);
}
@Update("update product set productNum=#{productNum},productName=#{productName}," +
"cityName=#{cityName},departureTime=#{departureTime},productPrice=#{productPrice}" +
",productDesc=#{productDesc},productStatus=#{productStatus} where id=#{id}")
void update(Product product);
<button type="button" class="btn bg-olive btn-xs" onclick='delOne(${product.id})'>删除button>
<script type="text/javascript">
function delOne(id){
if(confirm("您确定要删除吗?")){
location.href="${pageContext.request.contextPath}/product/delOne?id="+id;
}
}
script>
@RequestMapping("/delOne")
public String delOne(Integer id){
System.out.println(id);
productService.delById(id);
return "redirect:/product/findAll";
}
void delById(Integer id);
@Override
public void delById(Integer id) {
productDao.delById(id);
}
@Delete("delete from product where id=#{id}")
void delById(Integer id);
点删除之后提交表单最方便,哪些选中了,哪些未选中自动获取了!
注意form表单的标签只能放到table标签里面 不能放在否则报空指针 因为table标签内只允许有tr和td标签
<form action="${pageContext.request.contextPath}/product/delMany?" id="delForm">
<button type="button" class="btn btn-default" title="删除" onclick='delMany()'>
<i class="fa fa-trash-o">i> 删除
button>
form>
js删除
//TODO
//删除多个 直接提交表单最为方便
function delMany() {
//获取选中的复选框数量
var len = $("input:checkbox:checked").length;
//alert("你一共选中了"+len+"个复选框");
if(len>0&&confirm("您确定删除这些吗?")){
//获取表单
//document.forms 获取所有的表单 只有一个就是document.forms[0]
var delForm=$("#delForm");
//表单提交
delForm.submit();//提交了 和点submit效果一样
}
}
@RequestMapping("/delMany")
public String delMany(Integer[] ids){
System.out.println("删除所有:被删编号 "+Arrays.toString(ids));
productService.delMany(ids);
return "redirect:findAll";
}
ProductService接口
void delMany(Integer[] ids);
ProductServiceImpl实现
//根据ids数组删除多个
@Override
public void delMany(Integer[] ids) {
//dao内不需要再写个delMany方法了 in(1,2,3) 动态sql在注解内不大好写 不如把麻烦留在业务层 最灵活了
for (Integer id : ids) {
productDao.delById(id);
}
}
create sequence order_seq;
CREATE TABLE orders(
id number PRIMARY KEY,
orderNum VARCHAR2(20) NOT NULL UNIQUE,
orderTime DATE,
peopleCount number,
orderDesc VARCHAR2(500),
payType number,
orderStatus number,
productId int,
FOREIGN KEY (productId) REFERENCES product(id)
)
其中字段描述如下:
序号 | 字段名称 | 字段类型 | 字段描述 |
---|---|---|---|
1 | id | bigint | 无意义、主键自动增长 |
2 | orderNum | varchar(50) | 订单编号 不为空 唯一 |
3 | orderTime | DATE | 下单时间 |
4 | peopleCount | int | 出行人数 |
5 | orderDesc | varchar(500) | 订单描述(其它信息) |
6 | payType | int | 支付方式(0 支付宝 1 微信 2其它) |
7 | orderStatus | int | 订单状态(0 未支付 1 已支付) |
8 | productId | int | 产品id 外键 |
@Controller
@RequestMapping("/order")
public class OrderController {
@Autowired
OrderService orderService;
@RequestMapping("/findAll")
public ModelAndView findAll(){
List<Order> orders= orderService.findAll();
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("orders",orders);
modelAndView.setViewName("order-list");
return modelAndView;
}
}
OrderService接口
public interface OrderService {
List<Order> findAll();
}
OrderServiceImpl接口实现
@Service
public class OrderServiceImpl implements OrderService {
@Autowired
OrderDao orderDao;
@Override
public List<Order> findAll() {
return orderDao.findAll();
}
}
public interface OrderDao {
@Select("select * from orders")
List<Order> findAll();
}
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<table id="dataList" class="table table-bordered table-striped table-hover dataTable">
<thead>
<tr>
<th class="" style="padding-right: 0px;"><input
id="selall" type="checkbox" class="icheckbox_square-blue">
th>
<th class="sorting_asc">IDth>
<th class="sorting">订单编号th>
<th class="sorting">下单时间th>
<th class="sorting">出行人数th>
<th class="sorting">支付方式th>
<th class="sorting">订单状态th>
<th class="sorting">产品名称th>
<th class="text-center">操作th>
tr>
thead>
<tbody>
<c:forEach items="${orders}" var="order">
<tr>
<td><input name="ids" type="checkbox">td>
<td>${order.id}td>
<td>${order.orderNum}td>
<td>
<fmt:formatDate value="${order.orderTime}" pattern="yyyy-MM-dd HH:mm">fmt:formatDate>
td>
<td>${order.peopleCount}td>
<%--
支付宝 0
微信 1
其他 2
--%>
<td>${order.payType==0?"支付宝":order.payType==1?"微信":"其他"}td>
<td>${order.orderStatus==0?"未支付":"已支付"}td>
<td>${order.product.productName}td>
<td class="text-center">
<button type="button" class="btn bg-olive btn-xs"
onclick='location.href="${pageContext.request.contextPath}/pages/order-show.jsp"'>订单button>
<button type="button" class="btn bg-olive btn-xs"
onclick='location.href="${pageContext.request.contextPath}/pages/order-show.jsp"'>查看button>
td>
tr>
c:forEach>
tbody>
table>
新增订单页面需要准备产品的数据列表(选择产品的下拉选要从数据库中查,本次就不用ajax了,直接加个addUI还是简单的controller先查询再跳转 )
//要用就注入 别婆婆妈妈的
@Autowired
ProductService productService;
@RequestMapping("/addUI")
public ModelAndView addUI(){
List<Product> products = productService.findAll();
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("products",products);
modelAndView.setViewName("order-add");
return modelAndView;
}
<div class="col-md-2 title">选择产品div>
<div class="col-md-4 data">
<select class="form-control select2" style="width: 100%" name="product.id">
<c:forEach items="${ products }" var="p">
<option value="${ p.id }" >${ p.productName }option>
c:forEach>
select>
div>
@RequestMapping("/save")
public String save(Order order){
orderService.save(order);
return "redirect:/order/findAll";
}
OrderService接口
void save(Order order);
OrderServiceImpl接口实现
@Override
public void save(Order order) {
orderDao.save(order);
}
@Insert("insert into orders values(order_seq.nextval,#{orderNum},#{orderTime},#{peopleCount},#{orderDesc},#{payType},#{orderStatus},#{product.id})")
void save(Order order);