初始项目

main
bainan 3 months ago committed by nihao
parent bb2f356c7b
commit 6cceb3cc73

@ -0,0 +1,13 @@
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() {
System.out.println("1111");
return "showFirst";
}
}

@ -0,0 +1,22 @@
package com.ssm.controller;
import com.ssm.entity.ItemCategory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
@RequestMapping("itemCategory")
public class ItemCategoryController {
//对象方式接收数据ModelAndView对象响应数据
@RequestMapping("add")
public ModelAndView test(ItemCategory itemCategory){
//创建ModelAndView对象的同时设置了view的信息
ModelAndView mv=new ModelAndView("showItemCategory");
//将这个对象category保存到ModelAndView对象中
mv.addObject("itemCategoryInfo", itemCategory);
return mv;
}
}

@ -0,0 +1,18 @@
package com.ssm.controller;
import com.ssm.entity.Item;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("item")
public class ItemController {
//对象方式接收花卉信息
@RequestMapping("add")
public String test(Item item){
System.out.println("花卉信息:"+item.toString());
return "showItem";
}
}

@ -0,0 +1,219 @@
package com.ssm.entity;
/**
*
*/
public class Item {
/**
*
*/
private Integer id;
/**
*
*/
private String name;
/**
*
*/
private String price;
/**
*
*/
private Integer zk;
/**
*
*/
private Integer scNum;
/**
*
*/
private Integer gmNum;
/**
*
*/
private String url1;
/**
* 1
*/
private String url2;
/**
* 2
*/
private String url3;
/**
* 3
*/
private String url4;
/**
* 4
*/
private String url5;
/**
*
*/
private String ms;
/**
* id
*/
private ItemCategory yiji;
/**
* id
*/
private ItemCategory erji;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public Integer getZk() {
return zk;
}
public void setZk(Integer zk) {
this.zk = zk;
}
public Integer getScNum() {
return scNum;
}
public void setScNum(Integer scNum) {
this.scNum = scNum;
}
public Integer getGmNum() {
return gmNum;
}
public void setGmNum(Integer gmNum) {
this.gmNum = gmNum;
}
public String getUrl1() {
return url1;
}
public void setUrl1(String url1) {
this.url1 = url1;
}
public String getUrl2() {
return url2;
}
public void setUrl2(String url2) {
this.url2 = url2;
}
public String getUrl3() {
return url3;
}
public void setUrl3(String url3) {
this.url3 = url3;
}
public String getUrl4() {
return url4;
}
public void setUrl4(String url4) {
this.url4 = url4;
}
public String getUrl5() {
return url5;
}
public void setUrl5(String url5) {
this.url5 = url5;
}
public String getMs() {
return ms;
}
public void setMs(String ms) {
this.ms = ms;
}
public ItemCategory getYiji() {
return yiji;
}
public void setYiji(ItemCategory yiji) {
this.yiji = yiji;
}
public ItemCategory getErji() {
return erji;
}
public void setErji(ItemCategory erji) {
this.erji = erji;
}
@Override
public String toString() {
return "Item{" +
"id=" + id +
", name='" + name + '\'' +
", price='" + price + '\'' +
", zk=" + zk +
", scNum=" + scNum +
", gmNum=" + gmNum +
", url1='" + url1 + '\'' +
", url2='" + url2 + '\'' +
", url3='" + url3 + '\'' +
", url4='" + url4 + '\'' +
", url5='" + url5 + '\'' +
", ms='" + ms + '\'' +
// 输出一级商品分类名称
", yijiCategoryName=" + yiji.getName() +
// 输出二级商品分类名称
", erjiCategoryName=" + erji.getName() +
'}';
}
public void printInfo() {
//int i=10/0;//测试异常通知
System.out.println("产品名称:"+name+"\n产品售价"+price+
"\n一级分类编号"+yiji.getId()+
"\n一级分类名称"+yiji.getName()+
"\n二级分类编号"+erji.getId()+
"\n二级分类名称"+erji.getName());
}
}

@ -0,0 +1,60 @@
package com.ssm.entity;
/**
*
*/
public class ItemCategory {
/**
* id
*/
private Integer id;
/**
*
*/
private String name;
/**
* id
*/
private Integer pid;
/**
*
*/
private Integer isDelete;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getPid() {
return pid;
}
public void setPid(Integer pid) {
this.pid = pid;
}
public Integer getIsDelete() {
return isDelete;
}
public void setIsDelete(Integer isDelete) {
this.isDelete = isDelete;
}
}

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<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/tool http://www.springframework.org/schema/tool/spring-tool.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!-- 配置注解扫描器配置spring容器初始化对象时需要扫描的包 -->
<context:component-scan base-package="com.ssm.controller"></context:component-scan>
<!-- 配置视图解析器,ctrl+shift+t搜索类将return的字符串逻辑视图+前缀+后缀,转换成真正的物理视图 -->
<!-- 逻辑视图success,真正的视图:/WEB-INF/view/success.jsp -->
<!-- -->
<!-- 配置注解驱动 -->
<mvc:annotation-driven/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- 前缀 -->
<property name="prefix" value="/WEB-INF/view/"></property>
<!-- 后缀 -->
<property name="suffix" value=".jsp"></property>
</bean>
<bean class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
</bean>
</beans>

Binary file not shown.

Binary file not shown.

@ -0,0 +1,12 @@
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>展示入门程序信息</title>
</head>
<body>
Success!
</body>
</html>

@ -0,0 +1,31 @@
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>展示Controller接收及响应数据</title>
</head>
<body>
Success!
<br>
商品信息已在控制台输出!
<%--<br>--%>
<%--商品名称:${productInfo.pname}--%>
<%--<br>--%>
<%--是否热门:${productInfo.isHot}--%>
<%--<br>--%>
<%--市场价格:${productInfo.marketPrice}--%>
<%--<br>--%>
<%--销售价格:${productInfo.shopPrice}--%>
<%--<br>--%>
<%--商品图片:${productInfo.image}--%>
<%--<br>--%>
<%--分类名称:${productInfo.category.cname}--%>
<%--<br>--%>
<%--商品描述:${productInfo.pdesc}--%>
<%--<br>--%>
<%--上架日期:${productInfo.pdate}--%>
</body>
</body>
</html>

@ -0,0 +1,16 @@
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>展示花卉类目信息</title>
</head>
<body>
Success!
<br>
类目编号:${itemCategoryInfo.id}
<br>
类目名称:${itemCategoryInfo.name}
</body>
</html>

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>SpringMVCFirst</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>springDispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- 配置DispatcherServlet的初始化参数 -->
<init-param>
<param-name>contextConfigLocation</param-name>
<!-- 配置SpringMVC配置文件的位置和名称-->
<param-value>classpath:springmvc.xml</param-value>
</init-param>
<!-- 该servlet在第一次加载的时候就被创建而不是等请求时才创建 -->
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springDispatcherServlet</servlet-name>
<!-- 可以应答所有请求 -->
<url-pattern>/</url-pattern>
</servlet-mapping>
<!--编码过滤器,解决中文乱码问题-->
<filter>
<filter-name>characterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>

@ -0,0 +1,67 @@
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加花卉</title>
</head>
<body>
<form action="item/add" method="post">
<table>
<tr>
<td>花卉编号:</td>
<td width="20"></td>
<td><input type="text" name="id" placeholder="请输入花卉编号" /></td>
</tr>
<tr>
<td>花卉名称:</td>
<td width="20"></td>
<td><input type="text" name="name" placeholder="请输入花卉名称" /></td>
</tr>
<tr>
<td>花卉价格:</td>
<td width="20"></td>
<td><input type="text" name="price" value="" class="bg" placeholder="请输入花卉价格" /></td>
</tr>
<tr>
<td>折扣:</td>
<td width="20"></td>
<td><input type="text" name="zk" value="" placeholder="请输入折扣" /></td>
</tr>
<tr>
<td>花卉一级类目:</td>
<td width="20"></td>
<td><input type="text" name="yiji.name" placeholder="请输入一级类目" /></td>
</tr>
<tr>
<td>花卉二级类目:</td>
<td width="20"></td>
<td><input type="text" name="erji.name" placeholder="请输入二级类目" /></td>
</tr>
<tr>
<td>商品主图:</td>
<td width="20"></td>
<td><input type="file" name="url1" /></td>
</tr>
<tr>
<td>副图1</td>
<td width="20"></td>
<td><input type="file" name="url2" /></td>
</tr>
<tr>
<td>描述:</td>
<td width="20"></td>
<td><textarea name="ms" rows="5" cols="35"></textarea></td>
</tr>
<tr>
<td align="right"><input type="reset" value="重置"></td>
<td></td>
<td align="center">
<input type="submit" value="添加">
</td>
</tr>
</table>
</form>
</body>
</html>

@ -0,0 +1,19 @@
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加花卉类目信息</title>
</head>
<body>
<form action="itemCategory/add" method="post">
类目编号:<input type="text" name="id">
<br>
类目名称:<input type="text" name="name">
<br>
<input type="submit" value="添加">
</form>
</body>
</html>

@ -0,0 +1,12 @@
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>入门程序</title>
</head>
<body>
<a href="hello">hello world</a>
</body>
</html>
Loading…
Cancel
Save