-----------Spring+SpringMVC+SpringJDBC搭建web项目实现商品查询-----------
准备工作:创建商品数据库,以及商品表
#创建数据库 DROP DATABASE IF EXISTS goodsDB; CREATE DATABASE goodsDB; USE goodsDB; #创建商品表 goods #id number 商品编号,主键 #name Varchar2(50) 商品名称,非空 #Price Number 商品单价,非空 #Num number 商品库存,必须大于0 CREATE TABLE goods( id INT PRIMARY KEY, NAME VARCHAR(50), price DOUBLE NOT NULL, imgs VARCHAR(200), num INT ); #添加数据 #创建数据库 DROP DATABASE IF EXISTS goodsDB; CREATE DATABASE goodsDB; USE goodsDB; #创建商品表 goods #id number 商品编号,主键 #name Varchar2(50) 商品名称,非空 #Price Number 商品单价,非空 #Num number 商品库存,必须大于0 CREATE TABLE goods( id INT PRIMARY KEY, NAME VARCHAR(50), price DOUBLE NOT NULL, imgs VARCHAR(200), num INT ); #添加数据 INSERT INTO goods VALUES('10010','迪奥999',250,'dior999.gif',100); INSERT INTO goods VALUES('10020','阿玛尼405',288,'405.gif',50); INSERT INTO goods VALUES('10030','TF16',398,'tf16.jpg',80); INSERT INTO goods VALUES('10040','YSL1966',998,'ysl1966.jpg',20); SELECT * FROM goods; |
1.创建maven的web项目
2.打开pom.xml导入相关jar包依赖坐标 以及 打war包 插件
<dependencies> <!--spring-mvc--> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>6.0.6</version> </dependency> <!--注解--> <dependency> <groupId>jakarta.annotation</groupId> <artifactId>jakarta.annotation-api</artifactId> <version>2.1.1</version> </dependency> <!--javaee-web:servlet校验注解--> <dependency> <groupId>jakarta.platform</groupId> <artifactId>jakarta.jakartaee-web-api</artifactId> <version>9.1.0</version> <scope>provided</scope> </dependency> <!--jstl--> <dependency> <groupId>jakarta.servlet.jsp.jstl</groupId> <artifactId>jakarta.servlet.jsp.jstl-api</artifactId> <version>3.0.0</version> </dependency> <dependency> <groupId>org.glassfish.web</groupId> <artifactId>jakarta.servlet.jsp.jstl</artifactId> <version>2.0.0</version> </dependency> <!--jsckson--> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.15.0</version> </dependency> <!--jdbc--> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.25</version> </dependency> <!--spring-jdbc--> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>6.0.6</version> </dependency> |