SpringMvc+Spring+MyBatis+Maven+Ajax+Json注解开发 利用Maven的依赖导入不使用架包模式 (实操十)

简介: SpringMvc+Spring+MyBatis+Maven+Ajax+Json注解开发 利用Maven的依赖导入不使用架包模式 (实操十)

本文章的目标实现二个内容:


第一个任务完成:如何完成在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>

第一个任务完成:上面完成在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);

上面是原创图片禁止下载:

相关文章
|
1月前
|
XML Java 测试技术
Spring IOC—基于注解配置和管理Bean 万字详解(通俗易懂)
Spring 第三节 IOC——基于注解配置和管理Bean 万字详解!
135 26
|
4天前
|
SQL XML Java
一、MyBatis简介:MyBatis历史、MyBatis特性、和其它持久化层技术对比、Mybatis下载依赖包流程
一、MyBatis简介:MyBatis历史、MyBatis特性、和其它持久化层技术对比、Mybatis下载依赖包流程
102 68
|
2月前
|
缓存 Java 数据库
SpringBoot缓存注解使用
Spring Boot 提供了一套方便的缓存注解,用于简化缓存管理。通过 `@Cacheable`、`@CachePut`、`@CacheEvict` 和 `@Caching` 等注解,开发者可以轻松地实现方法级别的缓存操作,从而提升应用的性能和响应速度。合理使用这些注解可以大大减少数据库的访问频率,优化系统性能。
211 89
|
1月前
|
监控 Java Spring
SpringBoot:SpringBoot通过注解监测Controller接口
本文详细介绍了如何通过Spring Boot注解监测Controller接口,包括自定义注解、AOP切面的创建和使用以及具体的示例代码。通过这种方式,可以方便地在Controller方法执行前后添加日志记录、性能监控和异常处理逻辑,而无需修改方法本身的代码。这种方法不仅提高了代码的可维护性,还增强了系统的监控能力。希望本文能帮助您更好地理解和应用Spring Boot中的注解监测技术。
67 16
|
10月前
|
Java API Spring
Spring容器如何使用一个注解来指定一个类型为配置类型
Spring容器如何使用一个注解来指定一个类型为配置类型
97 0
|
3月前
|
Java Spring
【Spring】方法注解@Bean,配置类扫描路径
@Bean方法注解,如何在同一个类下面定义多个Bean对象,配置扫描路径
196 73
|
5月前
|
XML Java 数据格式
手动开发-简单的Spring基于注解配置的程序--源码解析
手动开发-简单的Spring基于注解配置的程序--源码解析
76 0
|
9月前
|
XML Java 数据格式
Spring5系列学习文章分享---第三篇(AOP概念+原理+动态代理+术语+Aspect+操作案例(注解与配置方式))
Spring5系列学习文章分享---第三篇(AOP概念+原理+动态代理+术语+Aspect+操作案例(注解与配置方式))
86 0
|
9月前
|
Java Spring
spring基于注解配置数据源
spring基于注解配置数据源
|
XML Java 数据格式
spring ioc中的一些常用annotation注解配置
spring ioc中的一些常用annotation注解配置

推荐镜像

更多