diff --git a/equipment-SpringMVCProject/src/com/ssm/controller/FirstController.java b/equipment-SpringMVCProject/src/com/ssm/controller/FirstController.java deleted file mode 100644 index 829dca6..0000000 --- a/equipment-SpringMVCProject/src/com/ssm/controller/FirstController.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.ssm.controller; - -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; - -@Controller -public class FirstController { - @RequestMapping("hello") - public String hello(){ - return "showFirst"; - } - -} diff --git a/equipment-SpringMVCProject/src/com/ssm/controller/Main.java b/equipment-SpringMVCProject/src/com/ssm/controller/Main.java deleted file mode 100644 index 021bb99..0000000 --- a/equipment-SpringMVCProject/src/com/ssm/controller/Main.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.ssm.controller; - -public class Main { -} diff --git a/equipment-SpringMVCProject/src/com/ssm/controller/ProductController.java b/equipment-SpringMVCProject/src/com/ssm/controller/ProductController.java new file mode 100644 index 0000000..7a43690 --- /dev/null +++ b/equipment-SpringMVCProject/src/com/ssm/controller/ProductController.java @@ -0,0 +1,19 @@ +package com.ssm.controller; + +import com.ssm.entity.Product; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; + +@Controller +@RequestMapping("/product") // 类级别的请求路径 +public class ProductController { + + // 接收addProduct.jsp表单提交的参数,直接封装成Product对象 + @RequestMapping("/add") + public String addProduct(Product product) { + // 控制台打印商品信息,和你的要求一致 + System.out.println("商品信息:" + product.toString()); + // 跳转到WEB-INF/view/showProduct.jsp页面 + return "showProduct"; + } +} \ No newline at end of file diff --git a/equipment-SpringMVCProject/src/com/ssm/entity/Category.java b/equipment-SpringMVCProject/src/com/ssm/entity/Category.java new file mode 100644 index 0000000..78fe575 --- /dev/null +++ b/equipment-SpringMVCProject/src/com/ssm/entity/Category.java @@ -0,0 +1,20 @@ +package com.ssm.entity; + +public class Category { + private String cname; // 分类名称 + + public String getCname() { + return cname; + } + + public void setCname(String cname) { + this.cname = cname; + } + + @Override + public String toString() { + return "Category{" + + "cname='" + cname + '\'' + + '}'; + } +} \ No newline at end of file diff --git a/equipment-SpringMVCProject/src/com/ssm/entity/Product.java b/equipment-SpringMVCProject/src/com/ssm/entity/Product.java new file mode 100644 index 0000000..1522e95 --- /dev/null +++ b/equipment-SpringMVCProject/src/com/ssm/entity/Product.java @@ -0,0 +1,117 @@ +package com.ssm.entity; + +import org.springframework.format.annotation.DateTimeFormat; + +import java.util.Date; + +public class Product { + private Integer pid; // 商品id + private String pname; // 商品名 + private Double marketPrice;// 商品单价 + private Double shopPrice; // 商城价 + private String image; // 商品图片 + private String pdesc; // 描述 + private Integer isHot; // 是否热门 + @DateTimeFormat(pattern = "yyyy-MM-dd") // 日期格式化,和你表单的日期格式匹配 + private Date pdate; // 上架日期 + private Category category; // 关联分类对象 + private Integer state = 0; // 状态 + + // Getter/Setter 方法(必须写,否则Spring无法自动注入参数) + public Integer getPid() { + return pid; + } + + public void setPid(Integer pid) { + this.pid = pid; + } + + public String getPname() { + return pname; + } + + public void setPname(String pname) { + this.pname = pname; + } + + public Double getMarketPrice() { + return marketPrice; + } + + public void setMarketPrice(Double marketPrice) { + this.marketPrice = marketPrice; + } + + public Double getShopPrice() { + return shopPrice; + } + + public void setShopPrice(Double shopPrice) { + this.shopPrice = shopPrice; + } + + public String getImage() { + return image; + } + + public void setImage(String image) { + this.image = image; + } + + public String getPdesc() { + return pdesc; + } + + public void setPdesc(String pdesc) { + this.pdesc = pdesc; + } + + public Integer getIsHot() { + return isHot; + } + + public void setIsHot(Integer isHot) { + this.isHot = isHot; + } + + public Date getPdate() { + return pdate; + } + + public void setPdate(Date pdate) { + this.pdate = pdate; + } + + public Category getCategory() { + return category; + } + + public void setCategory(Category category) { + this.category = category; + } + + public Integer getState() { + return state; + } + + public void setState(Integer state) { + this.state = state; + } + + // toString方法,控制台打印用,和你输出格式一致 + @Override + public String toString() { + return "Product{" + + "pid=" + pid + + ", pname='" + pname + '\'' + + ", marketPrice=" + marketPrice + + ", shopPrice=" + shopPrice + + ", image='" + image + '\'' + + ", pdesc='" + pdesc + '\'' + + ", isHot=" + isHot + + ", pdate=" + pdate + + ", categoryName=" + (category != null ? category.getCname() : null) + + ", state=" + state + + '}'; + } +} \ No newline at end of file diff --git a/equipment-SpringMVCProject/src/springmvc.xml b/equipment-SpringMVCProject/src/springmvc.xml index 8425f55..885e547 100644 --- a/equipment-SpringMVCProject/src/springmvc.xml +++ b/equipment-SpringMVCProject/src/springmvc.xml @@ -11,16 +11,15 @@ http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd"> - + - + - + - - + diff --git a/equipment-SpringMVCProject/web/WEB-INF/view/showProduct.jsp b/equipment-SpringMVCProject/web/WEB-INF/view/showProduct.jsp new file mode 100644 index 0000000..f3ce7fc --- /dev/null +++ b/equipment-SpringMVCProject/web/WEB-INF/view/showProduct.jsp @@ -0,0 +1,10 @@ +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + 结果页面 + + +

Success!

+

商品信息已在控制台输出!

+ + \ No newline at end of file diff --git a/equipment-SpringMVCProject/web/WEB-INF/web.xml b/equipment-SpringMVCProject/web/WEB-INF/web.xml index 0e6e292..9aaebf0 100644 --- a/equipment-SpringMVCProject/web/WEB-INF/web.xml +++ b/equipment-SpringMVCProject/web/WEB-INF/web.xml @@ -4,6 +4,25 @@ xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" version="4.0"> + + + encodingFilter + org.springframework.web.filter.CharacterEncodingFilter + + encoding + UTF-8 + + + forceEncoding + true + + + + encodingFilter + /* + + + DispatcherServlet org.springframework.web.servlet.DispatcherServlet diff --git a/equipment-SpringMVCProject/web/addProduct.jsp b/equipment-SpringMVCProject/web/addProduct.jsp new file mode 100644 index 0000000..462faca --- /dev/null +++ b/equipment-SpringMVCProject/web/addProduct.jsp @@ -0,0 +1,59 @@ +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + 添加商品 + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
商品编号:
商品名称:
是否热门: + +
市场价格:
销售价格:
商品图片:
分类名称:
商品描述:
上架日期:
+ +
+
+ + \ No newline at end of file