慕课网 《轻松愉快之玩转SpringData》学习总结1

时间:2019年05月05日星期日
说明:本文内容均来自慕课网。@慕课网:http://www.imooc.com
部分参 https://segmentfault.com/a/1190000009211986
仅个人学习总结。如产生异议,请联系2964388297@qq.com。

第一章:课程介绍

Spring Data 概览

什么是Spring Data

主旨:provide a familiar and consistent, Spring-based programming model for data access
(提供一个熟悉的、一致的,基于Spring框架的数据访问框架。简化数据库的访问)
历史:历史:2010年提出,作者Rod Johnso,Spring Source项目
官方网址:http://projects.spring.io/spring-data/#quick-start(学习的一手资料)


RDBMS关系型数据库,MongoDB非关系型数据库,JDBC–>JPA(mongoDB java Driver)–>Spring Data(CrudRepository增加(Create,读取查询(Retrieve),更新(Update)和删除(Delete)PagingAndSortingRepository分页和排序)

Spring Data包含多个子项目

Spring Data JPA (减少数据访问层的操作)
Spring Data MongoDB (基于分布式的数据存储的数据库)
Spring Data Redis (C语言编写、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库,并提供多种语言的API)
Spring Data Solr(一个高性能,采用Java5开发,基于Lucene的全文搜索服务器,提供webUI)

课程安排

传统方式访问数据库(1.通过最原始的JDBC的方式操作 2.通过spring JDBC的方式操作)
Spring Data 快速起步
Spring DataJPA进阶
Spring Data JPA高级

第二章:使用传统方式访问数据库

2-1通过最原始的JDBC的方式操作

每个框架都有自己的使用场景,一个场景有多种解决法案。

传统方式访问数据库

JDBC
Spring JdbcTemplate
弊端分析

JDBC

Connection(连接)
Statement (Statement 是 Java 执行数据库操作的一个重要接口,用于在已经建立数据 库连接的基础 上,向数据库发送要执行的SQL语句。Statement对象,用于执行不带参数的简单SQL语句)
ResultSet (数据库结果集的数据表,通常通过执行查询数据库的语句生成,结果集–>遍历)
Test Case (Junit 测试,一个一个测试)

搭建开发环境

创建Maven项目
添加数据库驱动和单元测试依赖
数据库表的准备,使用mysql数据库

开始创建一个Java项目,完成第二章的目录结构如下:
在这里插入图片描述
1.在pom.xml文件中添加依赖
mvnrepository网址:https://mvnrepository.com/
MySql Driver的依赖(如果你是通过MySql install安装,一般为教新的版本,选靠前的版本就行)

<dependency>
  <groupId>mysql</groupId>
  <artifactId>mysql-connector-java</artifactId>
  <version>8.0.13</version>
</dependency>

Junit的依赖(这个一般会自动导入)

 <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>

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>com.imooc</groupId>
  <artifactId>springdata</artifactId>
  <version>1.0-SNAPSHOT</version>



  <name>springdata</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.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
  </properties>

  <dependencies>
    <!--MySQL Driver-->
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>8.0.13</version>
    </dependency>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>

    <!--spring-jdbc-->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-jdbc</artifactId>
      <version>4.3.14.RELEASE</version>
    </dependency>
    <!--spring-context-->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>4.3.14.RELEASE</version>
    </dependency>


  </dependencies>

  <build>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_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-jar-plugin</artifactId>
          <version>3.0.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>
        <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
        <plugin>
          <artifactId>maven-site-plugin</artifactId>
          <version>3.7.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-project-info-reports-plugin</artifactId>
          <version>3.0.0</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

2.创建数据库
最好自己敲一遍,数据库的安装不在此介绍
创建数据库

  create database spring_data;

创建表

    create table student(
    id int not null auto_increment,
    name varchar(20) not null ,
    age int not null,
    primary key (id)
    );

3.开发JDBCUtil工具类
获取Connection ,关闭Connection ,Statement,ResultSet
注意事项:配置的属性放置配置文件中,然后通过代码的方式将配置文件中的数据加载进来即可。

1.具体代码:(直接在代码中配置属性url,user,password,driverClass)

package com.imooc.util;
import java.io.IOException;
import java.io.InputStream;
import java.sql.*;
import java.util.Properties;

/**
 * JDBC工具类
 * 1)获取connection
 * 2)释放资源
 */

public class JDBCUtil {
    /**
     * 获取Connection
     * @return 所获取到的JDBC的Connection
     */
    public static Connection getConnection() throws IOException {
        /**
         * 不建议把配置硬编码到代码中
         * 最佳实践:配置性的建议写到配置文件中
         */
        String url = "jdbc:mysql:///spring_data?serverTimezone=UTC ";
        String user = "root";
        String password = "915099" ;
        String driverClass = "com.mysql.cj.jdbc.Driver"

        try {
            Class.forName(driverClass);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        Connection connection = null;
        try {
            connection = DriverManager.getConnection(url, user ,password );
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return connection ;
    }

    /**
     * 释放db相关的资源
     * @param resultSet
     * @param statement
     * @param connection
     */
    public static void release(ResultSet resultSet,
                               Statement statement, Connection connection){
        if(resultSet != null ){
            try {
                resultSet.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if(statement != null ){
            try {
                resultSet.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if(connection != null ){
            try {
                resultSet.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

    }
}

2.具体代码:(在resources文件添加db.properties,配置的属性放置配置文件db.properties中,然后通过代码的方式将配置文件中的数据加载进来)
db.properties文件的具体代码:

jdbc.url = jdbc:mysql:///spring_data?serverTimezone=UTC
jdbc.user = root
jdbc.password = 915099
jdbc.driverClass = com.mysql.cj.jdbc.Driver

注意:有人可能会说url,driverClass和视频中的不一样
使用jdbc.url = jdbc:mysql:///spring_data时,会报错

java.sql.SQLException: The server time zone value ‘Öйú±ê׼ʱ¼ä’ is
unrecognized or represents more than one time

使用 jdbc.driverClass = com.mysql.jdbc.Driver,会报错

Loading class com.mysql.jdbc.Driver'. This is deprecated. The new driver class iscom.mysql.cj.jdbc.Driver’. The driver is
automatically registered via the SPI and manual loading of the driver
class is generally unnecessary.

以上参考博文链接:https://www.cnblogs.com/cn-chy-com/p/10145690.html

具体代码:(完整代码,两种方式注释到一个即可)

package com.imooc.util;
import java.io.IOException;
import java.io.InputStream;
import java.sql.*;
import java.util.Properties;

/**
 * JDBC工具类
 * 1)获取connection
 * 2)释放资源
 */

public class JDBCUtil {
    /**
     * 获取Connection
     * @return 所获取到的JDBC的Connection
     */
    public static Connection getConnection() throws IOException {
        /**
         * 不建议把配置硬编码到代码中
         * 最佳实践:配置性的建议写到配置文件中
         */
//        String url = "jdbc:mysql:///spring_data?serverTimezone=UTC ";
//        String user = "root";
//        String password = "915099" ;
//        String driverClass = "com.mysql.cj.jdbc.Driver";

        InputStream inputStream = JDBCUtil.class.getClassLoader().getResourceAsStream("db.properties");
        Properties properties = new Properties();
        properties.load(inputStream);

        String url = properties.getProperty("jdbc.url");
        String user = properties.getProperty("jdbc.user");
        String password = properties.getProperty("jdbc.password");
        String driverClass  = properties.getProperty("jdbc.driverClass");
        try {
            Class.forName(driverClass);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        Connection connection = null;
        try {
            connection = DriverManager.getConnection(url, user ,password );
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return connection ;
    }

    /**
     * 释放db相关的资源
     * @param resultSet
     * @param statement
     * @param connection
     */
    public static void release(ResultSet resultSet,
                               Statement statement, Connection connection){
        if(resultSet != null ){
            try {
                resultSet.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if(statement != null ){
            try {
                resultSet.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if(connection != null ){
            try {
                resultSet.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

    }
}

JDBCUtilTest的具体代码:

package com.imooc.util;
import org.junit.Assert;
import org.junit.Test;
import java.sql.Connection;
public class JDBCUtilTest {

    @Test
    public void testGetConnection() throws Exception {
        Connection connection = JDBCUtil.getConnection();
        Assert.assertNotNull(connection);
    }
}

注意:idea自动创建项目时可能没有resources文件,这时要注意到resources是在Java下面,自行创建。

 InputStream inputStream = JDBCUtil.class.getClassLoader().getResourceAsStream("db.properties");

4.建立对象模型,DAO层开发(数据访问对象)
1.对象模型domain

package com.imooc.domain;

/**
 * Student实体类
 */

public class Student {
    /**
     * 主键字段
     */
    private int id;
    /**
     * 姓名
     */
    private String name;
    /**
     * 年龄
     */
    private int age;
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
}

2.dao层开发
接口interface StudentDAO

    package com.imooc.dao;
    import com.imooc.domain.Student;
    import java.util.List;
    /**
     * StudentDAO访问接口
     */
    
    public interface StudentDAO {
        /**
         * 查询所有学生
         * @return 所有学生
         */
        public List<Student> query();
    
        /**
         * 添加一个学生
         * @param student 待添加的学生
         */
        public void save(Student student);
    }

3.接口实现 StudentDAOImpl

package com.imooc.dao;
import com.imooc.domain.Student;
import com.imooc.util.JDBCUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

/**
 * StudentDao访问接口实现类:通过最原始的JDBC的方式操作
 */

public class StudentDAOImpl  implements StudentDAO {
    @Override
    public List<Student> query() {

        List<Student> students = new ArrayList<Student>();
        Connection connection = null ;
        PreparedStatement preparedStatement = null ;
        ResultSet resultSet = null ;
        String sql = "select id ,name ,age from student";
        try {
            connection = JDBCUtil.getConnection();
            preparedStatement = connection.prepareStatement(sql);
            resultSet = preparedStatement.executeQuery();
            Student student = null;

            while ( resultSet.next() ){
               int id = resultSet.getInt("id");
               String name = resultSet.getString("name");
               int age = resultSet.getInt("age");

               student = new Student();
               student.setId(id);
               student.setName(name);
               student.setAge(age);

               students.add(student);

           }

        } catch (Exception e) {
            e.printStackTrace();
        }
        finally {
            JDBCUtil.release(resultSet, preparedStatement,connection );
        }
        return students;
    }

    @Override
    public void save(Student student) {

        Connection connection = null ;
        PreparedStatement preparedStatement = null ;
        ResultSet resultSet = null ;
        String sql = "insert into student (name, age) values (?,?) ";
        try {
            connection = JDBCUtil.getConnection();//建立连接
            preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1, student.getName());
            preparedStatement.setInt(2, student.getAge());
            preparedStatement.executeUpdate();


        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}

4.StudentDAOImplTest

package com.imooc.dao;

import com.imooc.domain.Student;
import org.junit.Test;
import java.util.List;

public class StudentDAOImplTest  {
    @Test
    public void testQuery()  {
            StudentDAO studentDAO = new StudentDAOImpl();
            List<Student> students = studentDAO.query();
        /**
         * for循环遍历一下,查看是否与数据库的数据一致
         */
        for (Student student :students ) {
                System.out.println("id:" + student.getId()
                        + ", name:" + student.getName() +
                        ", age:" + student.getAge());
            }

    }

    @Test
    public void Testsave()  {
        StudentDAO studentDAO = new StudentDAOImpl();
        Student student = new Student() ;
        student.setName("Libin");
        student.setAge(23);
        studentDAO.save(student);
    }
}

2-5.使用Spring JdbcTemplate

Maven 依赖
DataSource&JdbcTemplate注入
Test Case

1.pom.xml
Maven依赖idea会自动导入
jdbc需要自己导入
具体配置如下:

<?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>com.imooc</groupId>
  <artifactId>springdata</artifactId>
  <version>1.0-SNAPSHOT</version>



  <name>springdata</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.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
  </properties>

  <dependencies>
    <!--MySQL Driver-->
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>8.0.13</version>
    </dependency>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>

    <!--spring-jdbc-->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-jdbc</artifactId>
      <version>4.3.14.RELEASE</version>
    </dependency>
    <!--spring-context-->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>4.3.14.RELEASE</version>
    </dependency>


  </dependencies>

  <build>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_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-jar-plugin</artifactId>
          <version>3.0.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>
        <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
        <plugin>
          <artifactId>maven-site-plugin</artifactId>
          <version>3.7.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-project-info-reports-plugin</artifactId>
          <version>3.0.0</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

2.加入spring的配置文件,在resources创建beans.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"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd ">
<bean id = "dataSource" class = "org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="com.mysql.cj.jdbc.Driver"/>
    <property name="username" value="root"/>
    <property name="password" value="915099"/>
    <property name="url" value="jdbc:mysql:///spring_data?serverTimezone=UTC" />
</bean>
    <bean id ="jdbcTemplate" class = "org.springframework.jdbc.core.JdbcTemplate">
    <property name="dataSource" ref="dataSource"/>


</beans>

3.DataSourceTest测试

  package com.imooc;
    
    import org.junit.After;
    import org.junit.Assert;
    import org.junit.Before;
    import org.junit.Test;
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    import org.springframework.jdbc.core.JdbcTemplate;
    
    import javax.sql.DataSource;
    
    public class DataSourceTest {
        private ApplicationContext cxt =null ;
        @Before
        public void setup(){
            cxt = new ClassPathXmlApplicationContext("beans.xml");
            System.out.println("setup");
        }
        @After
        public void tearDown(){
            cxt = null ;
            System.out.println("tearDown");
        }
        @Test
        public void testDataSource(){
            System.out.println("testDataSource");
            DataSource dataSource = (DataSource)cxt.getBean("dataSource");
            Assert.assertNotNull(dataSource);
    
        }
        @Test
        public void TestJDBCTemplate(){
            System.out.println("testDataSource");
            JdbcTemplate jdbcTemplate = (JdbcTemplate) cxt.getBean("jdbcTemplate");
            Assert.assertNotNull(jdbcTemplate);
    
        }
    
    }

4.StudentDAOSpringJdbcImpl
在pom.xml中加入jdbcTemplate的依赖

  </bean>
        <bean id="studentDAO" class="com.imooc.dao.StudentDAOSpringJdbcImpl">
            <property name="jdbcTemplate" ref="jdbcTemplate"/>
        </bean>

创建StudentDAOSpringJdbcImpl

package com.imooc.dao;

import com.imooc.domain.Student;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowCallbackHandler;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * StudentDao访问接口实现类:通过spring JDBC的方式操作
 */

public class StudentDAOSpringJdbcImpl implements StudentDAO{
    private JdbcTemplate jdbcTemplate;

    @Override
    public List<Student> query() {
        final List<Student> students = new ArrayList<Student>();
        String sql = "select id ,name ,age from student";
        jdbcTemplate.query(sql, new RowCallbackHandler() {
            @Override
            public void processRow(ResultSet resultSet) throws SQLException {
                int id = resultSet.getInt("id");
                String name = resultSet.getString("name");
                int age = resultSet.getInt("age");

                Student student = new Student();
                student.setId(id);
                student.setName(name);
                student.setAge(age);

                students.add(student);//内部类,添加一个final

            }
        });
        return students;
    }

    @Override
    public void save(Student student) {
        String sql = "insert into student (name, age) values (?,?) ";
        jdbcTemplate.update(sql, new Object[]{student.getName(), student.getAge()});

    }



    public JdbcTemplate getJdbcTemplate() {
        return jdbcTemplate;
    }

    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }
}

5.StudentDAOSpringJdbcImplTest

package com.imooc.dao;

import com.imooc.domain.Student;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;
import java.util.List;

public class StudentDAOSpringJdbcImplTest {

    private ApplicationContext cxt =null ;
    private StudentDAO studentDAO = null ;

    @Before
    public void setup(){
        cxt = new ClassPathXmlApplicationContext("beans.xml");
        studentDAO = (StudentDAO)cxt.getBean("studentDAO");
        System.out.println("setup");
    }
    @After
    public void tearDown(){
        cxt = null ;
        System.out.println("tearDown");
    }
    @Test
    public void testDataSource(){
        System.out.println("testDataSource");
        DataSource dataSource = (DataSource)cxt.getBean("dataSource");
        Assert.assertNotNull(dataSource);

    }
    @Test
    public void TestJDBCTemplate(){
        System.out.println("testDataSource");
        JdbcTemplate jdbcTemplate = (JdbcTemplate) cxt.getBean("jdbcTemplate");
        Assert.assertNotNull(jdbcTemplate);

    }
    @Test
    public void testQuery()  {
            List<Student> students = studentDAO.query();
        /**
         * for循环遍历一下,查看是否与数据库的数据一致
         */
        for (Student student :students ) {
                System.out.println("id:" + student.getId()
                        + ", name:" + student.getName() +
                        ", age:" + student.getAge());
            }
    }

    @Test
    public void Testsave()  {
        Student student = new Student() ;
        student.setName("R");
        student.setAge(18);
        studentDAO.save(student);
    }
}

6.查询的结果
在这里插入图片描述
2-6 弊端分析

DAO里面代码量太多
DAO的实现有很多重复代码
开发分页和其它功能,需要重新进行封装

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
【2021年,将Spring全家桶系列课程进行Review,修复顺序等错误。进入2022年,将Spring的课程进行整理,整理为案例精讲的系列课程,并新增高级的Spring Security等内容,通过手把手一步步教你从零开始学会应用Spring,课件将逐步进行上传,敬请期待】 本课程是Spring案例精讲课程的第五部分Spring DataSpring案例精讲课程以真实场景、项目实战为导向,循序渐进,深入浅出的讲解Java网络编程,助力您在技术工作中更进一步。 本课程聚焦Spring Data的核心知识点:Spring Data Repository、Spring Data JPA(增删改查案例、实体自动生成数据库表、增加新的Repository方法、分页、排序、@NamedQuery、@Query及其分页和排序及参数设置、@NamedEntityGragh实现多对多映射、及QueryHints等)、Spring Data JDBC(增删改查案例、@Query等)的案例介绍, 快速掌握Spring Data的核心知识,快速上手,为学习及工作做好充足的准备。 由于本课程聚焦于案例,即直接上手操作,对于Spring的原理等不会做过多介绍,希望了解原理等内容的需要通过其他视频或者书籍去了解,建议按照该案例课程一步步做下来,之后再去进一步回顾原理,这样能够促进大家对原理有更好的理解。 【通过Spring全家桶,我们保证你能收获到以下几点】 1、掌握Spring全家桶主要部分的开发、实现2、可以使用Spring MVC、Spring Boot、Spring Cloud及Spring Data进行大部分的Spring开发3、初步了解使用微服务、了解使用Spring进行微服务的设计实现4、奠定扎实的Spring技术,具备了一定的独立开发的能力  【实力讲师】 毕业于清华大学软件学院软件工程专业,曾在Accenture、IBM等知名外企任管理及架构职位,近15年的JavaEE经验,近8年的Spring经验,一直致力于架构、设计、开发及管理工作,在电商、零售、制造业等有丰富的项目实施经验  【本课程适用人群】如果你是一定不要错过!  适合于有JavaEE基础的,如:JSP、JSTL、Java基础等的学习者没有基础的学习者跟着课程可以学习,但是需要补充相关基础知识后,才能很好的参与到相关的工作中。 【Spring全家桶课程共包含如下几门】5. 进阶篇:SpringData 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值