采用的的技术如下图所示
本文章的目标实现二个内容:
第一个任务完成:如何完成在Maven项目中的SSM环境搭建?
第二个任务完成:如何建立起自己的数据库建立起自己的数据库中表的数据?
采用的技术有:开发工具IDEA SpringMvc Spring MyBatis Maven Ajax Json 前端的Html Css Jquery 注解的方式开发
提出自己的问题?
如何查序淘宝订单管理系统的所有信息
分析数据库的表中的信息?
1 在数据库的表中什么是字段?
答:在表中的一个个的单元格,称为字段通俗来讲 如果将一个个的单元格当成一个点的话 二维直角坐标X Y 轴的交点
2 在数据库的表中什么是记录?
答:一条记录中有多个单元格 多个字段
3 如果查序的是一条记录多个字段的时 在Java中利用什么方式存放起来呢?
答:Map 集合来存 <Map<String, String>> map = service.getList();
4 如果查序的是多条记录在一条记录中多个字段的时 在Java中利用什么方式存放起来呢?
答:List中套用Map集合 List<Map<String, String>> list = service.getList();
在构建maven项目的时候我们要在Pom.xml文件中导入以下依赖坐标
官网:https://mvnrepository.com/artifact/com.networknt/service/2.1.1
1 Spring框架
<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.3.23</version>
</dependency>
2 Spring Web 框架的依赖
<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.3.23</version>
</dependency>
3 MyBatis 框架的依赖
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.10</version>
</dependency>
4 Jquery的依赖
<!-- https://mvnrepository.com/artifact/org.webjars.bower/jquery -->
<dependency>
<groupId>org.webjars.bower</groupId>
<artifactId>jquery</artifactId>
<version>3.6.1</version>
</dependency>
5 Junit的依赖
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
6 Service的依赖
<!-- https://mvnrepository.com/artifact/com.networknt/service -->
<dependency>
<groupId>com.networknt</groupId>
<artifactId>service</artifactId>
<version>2.1.1</version>
</dependency>
7 druid-1.1.20的依赖
<!-- https://mvnrepository.com/artifact/com.alibaba/druid -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.2.12</version>
</dependency>
上面的7步导入依赖等价于上个学期的架包的方式:
官网:https://mvnrepository.com/artifact/com.networknt/service/2.1.1
在resources文件中开始配置三个框架的配置文件信息 在后面学习了SpringBoot配置文件可能省略
下面配置文件是 applicationContext.xml文件配置信息
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
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/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!--开启组件扫描 -->
<context:component-scan
base-package="Com.Orders.Service" />
<!-- 引入外面的properties常量配置文件 -->
<context:property-placeholder
location="classpath:db.properties" />
<!-- 数据源配置 -->
<bean id="dataSource"
class="com.alibaba.druid.pool.DruidDataSource">
<property name="driverClassName" value="${jdbc.driver}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<!-- 事务管理器 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 开启基于注解配置的事务管理 -->
<tx:annotation-driven
transaction-manager="transactionManager" />
<!-- 扫描mapper接口文件 -->
<bean id="mapperScannerConfigurer"
class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="Com.Orders.Dao" />
</bean>
<!-- 创建sqlSession工厂 -->
<bean id="sessionFactory"
class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- <property name="typeAliasesPackage" value="com.yhh.domain" /> -->
<!-- 如果还有一些专门针对于mybatis的配置,需要引入 -->
<property name="configLocation"
value="classpath:mybatis-config.xml" />
<!-- 配置mybatis分页插件PageHelper -->
<property name="plugins">
<array>
<bean class="com.github.pagehelper.PageInterceptor">
<property name="properties">
<value></value>
</property>
</bean>
</array>
</property>
</bean>
</beans>
下面的文件是 SpringMvc框架的配置信息
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
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/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!--开启组件扫描 -->
<context:component-scan
base-package="Com.Orders.Controller" />
<!--开启mvc注解支持 -->
<mvc:annotation-driven />
<!--释放静态资源 -->
<mvc:default-servlet-handler />
</beans>
下面的文件是 MyBatis框架配置文件信息
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
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/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!--开启组件扫描 -->
<context:component-scan
base-package="Com.Orders.Controller" />
<!--开启mvc注解支持 -->
<mvc:annotation-driven />
<!--释放静态资源 -->
<mvc:default-servlet-handler />
</beans>
SSM三层的架构信息
第一个任务完成:上面完成在Maven项目中的SSM环境搭建
第二个任务完成:建立起自己的数据库建立起自己的数据库中表的数据
ROP TABLE IF EXISTS `orders`;
CREATE TABLE `orders` (
`id` int NOT NULL AUTO_INCREMENT COMMENT '订单编号',
`name` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '用户名称',
`foondname` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '商品名称',
`ordertime` varchar(22) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '订单时间',
`count` int NOT NULL COMMENT '数量',
`price` double(10, 2) NOT NULL COMMENT '商品价格',
`amount` double(255, 2) NOT NULL COMMENT '金额',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 10 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;
-- ----------------------------
INSERT INTO `orders` VALUES (1, '笔记本', 'Deal', '2022.8.12', 3456, 1234.00, 3459.00);
INSERT INTO `orders` VALUES (2, '书本', '人生的意义', '2022.3.24', 2345, 4566.00, 1234.00);
INSERT INTO `orders` VALUES (3, '手机', 'HuWei', '2022.3.21', 4567, 45678.00, 2345.00);
INSERT INTO `orders` VALUES (4, '漫画书', '三毛', '2022.1.4', 6789, 3245.00, 1234.00);
INSERT INTO `orders` VALUES (5, '电视机', '电信', '2022.3.4', 9087, 4532.00, 2346.00);
INSERT INTO `orders` VALUES (6, '电脑', '华为', '2022.6.7', 34566, 3452.00, 1234.00);
上面是原创图片禁止下载: