903spring springmvc mybatis integration springboot

Posted by dokueki@gmail.com on Fri, 03 Sep 2021 20:52:44 +0200

This is the controller, the servlet

spring is earlier than mybatis

To integrate spring with mybatis

Bridging spring and mybatis  Necessary 

 Importing spring transaction eliminates manual commit

ref refers to other people's classes to introduce class objects

value is a string property, just plug it into a string

 Omit these steps

 

spring indirectly manages mybatis

Shortcut tools for small and medium-sized projects

Large projects still use a lot of configuration xml

Tools are more complex and flexible

Fixed Route

Code

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       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/mvc
                         http://www.springframework.org/schema/mvc/spring-mvc.xsd
                         http://www.springframework.org/schema/tx
                         http://www.springframework.org/schema/tx/spring-tx.xsd
">
    <context:annotation-config></context:annotation-config>
    <context:component-scan base-package="com.njbdqn.ss"></context:component-scan>
    <!--start-up springmvc Annotation mode-->
    <mvc:annotation-driven></mvc:annotation-driven>
    <!--The following are mybatis Integration of Connected Databases-->
    <!--Configure a data source druid Link Pool Configuration-->
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
        <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property>
        <property name="url" value="jdbc:oracle:thin:@192.168.100.151:1521:orcl"></property>
        <property name="username" value="cm"></property>
        <property name="password" value="ok"></property>
        <property name="initialSize" value="30"></property>
        <property name="maxActive" value="1000"></property>
        <property name="minIdle" value="30"></property>
        <property name="maxWait" value="100000"></property>

    </bean>
    <!--Automatic transactions allow users not to commit-->
    <!--Configure Transaction Manager-->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"></property>
    </bean>
    <!--AutoComment Automation Transaction-->
    <tx:annotation-driven transaction-manager="transactionManager"></tx:annotation-driven>
    <!--To configure spring and mybatis integration-->
    <!--This factory is not mybatis Of SqlSessionFactory This is a class of third parties-->
    <bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"></property>
        <property name="mapperLocations" value="classpath*:mapper/*.xml"></property>
    </bean>
    <!--Scan all dao Interface-->
    <bean id="scannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.njbdqn.ss.dao"></property>
    </bean>


</beans>

web.xml

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >
 <!--notice tomcat Server Startup spring and springmvc-->

<web-app>
  <display-name>Archetype Created Web Application</display-name>
  <!--To configure spring.xml variable-->
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:spring.xml</param-value>
  </context-param>

  <!--start-up spring-->
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <!--start-up spring mvc Put all.do All methods are converted to servlet-->

  <servlet>
    <servlet-name>springmvc</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:spring.xml</param-value>
    </init-param>

  </servlet>
  <servlet-mapping>
    <servlet-name>springmvc</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>
</web-app>

 

 pom.xml

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>org.example</groupId>
  <artifactId>ss</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>ss Maven Webapp</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <spring.version>4.3.8.RELEASE</spring.version>
  </properties>


  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.mybatis/mybatis-spring -->
    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis-spring</artifactId>
      <version>1.3.2</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.alibaba/druid -->
    <dependency>
      <groupId>com.alibaba</groupId>
      <artifactId>druid</artifactId>
      <version>1.1.10</version>
    </dependency>
    <dependency>
      <groupId>com.oracle</groupId>
      <artifactId>ojdbc6</artifactId>
      <version>11.2.0.1.0</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis</artifactId>
      <version>3.4.6</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-core</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.springframework/spring-beans -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-beans</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.springframework/spring-tx -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-tx</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-jdbc</artifactId>
      <version>${spring.version}</version>
    </dependency>




    <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-core</artifactId>
      <version>2.9.8</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
      <version>2.9.8</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-annotations -->
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-annotations</artifactId>
      <version>2.9.8</version>
    </dependency>

  </dependencies>

  <build>
    <finalName>ss</finalName>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-war-plugin</artifactId>
          <version>3.2.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

bank.xml

 

 

 

 

 Effect

 

 The reason the value is not found here is that there are four data with id=4 in the database  But only one return can cause an error

Spring boot

 No more packages to import

springboot

Change the pom.xml file

Remember to modify several places to set javacompiler  There is also product structure  Even maven in setting s

 These are written inside the leaflets

Change to

SSM By Project  Project uses SSM springboot to see designer regulations

Using springboot instead of ssm, there is an architect for the entire project project.

The project is small as long as the data interface is exposed  Just use boot

If the business needs of the project become very large one day.Consider ssm for flexibility

springboot Small and Medium-sized Companies

General Exposure Data Interface

Truly large projects or micro services can use annotation syntax.

People who learn java must learn microservices later!Learn this before you know why you can be so lazy

There will be little SSH now

SSM is basically what you see outside

Micro-services are small modules of small services that are temporarily put together when they are split into many small pieces for use

In addition to design mode, there are algorithms that can toss around java virtual machines  Can become more metamorphic

As a high-level framework for frameworks  springcloud is the most advanced

springboot play

 

 Effect

 Not writing getset will result in no serialization errors

The space here should follow the specifications

Three-tier structure control layer, business logic service layer  ,dao layer data layer (data link layer)

classpath under current project path

 

Structure is always a three-tiered structure

The bottom level of SSM and boot doesn't have to be studied!

This low-level source takes too much time to write by hand, at least half a month to understand it is not easy!

Knowing the three-tier structure is enough to understand what MVC is capable of doing!!

mybatis spelling statement

Can achieve the effect of these six sentences

 Rough and simple.Additions, deletions, and alterations are required

Do not write this if you check it alone

People in java

Write these more than 100 times

Do you want to practice the basic skills 10 times?  Change a few more tables to practice

Final check to see if we can connect the two tables

Add add delete check function

 

 

Many times later it will be programming for Baidu

IDEA Inside Window Quick Switch Shortcut

ctrl plus tap

Specialized Data Generation Tools

How can the front end point the page to smuggle the log in?!

Buried point

Six years for 30,000 yuan a month?!

The best thing to do is write redis till evening

Front End Buried Points are manufactured according to user specifications

Data burying requires front-end and back-end collaboration 

I'm doing data analysis

One is a large amount of data in the database

Second, buried sites provide a large amount of data, and Party A provides user behavior logs, they have buried points.

Big data engineers don't need to know how to bury the dot. They generate a log file every day, at least once you've seen one

The main thing is that you need to know how this billion pieces of data are generated!!

Big data engineers know where data sources come from.How come user information is buried

Later you can dig and analyze!

At least tell it.

Three sources of data  1 Database source (most used)

                        2 Buried points (know how to get there)

                        3

Front end with ajax Backend with redis at night and then slowly with random access

We use data

Whether ssm or boot in one hour  Add/delete changes found in database

 

 Design sketch

Topics: Java html5 html