Spring Boot Mybatis 를 사용 하여 역방향 공 사 를 하 는 절차

1.프로젝트 의 루트 디 렉 터 리 에 Mybatis 역방향 프로젝트 프로필 복사

2.프로젝트 및 표 의 상황 에 따라 Generator Mapper.xml 설정 을 수정 합 니 다.
  • 높 은 버 전 을 사용 하면 구동 류 는 com.my sql.cj.jdbc.Driver
  • 으로 변 합 니 다.
  • url 뒤에 속성 nullCatalogMeansCurrent=true 를 추가 해 야 합 니 다.그렇지 않 으 면 문제 가 생 성 됩 니 다
  • 현재 버 전 MySQL 데이터베이스 5.7
    주로 주석 에 따라 자신의 내용 을 수정 합 니 다.
    
    <?xml version="1.0" encoding="UTF-8"?> 
    <!DOCTYPE generatorConfiguration 
     
        PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" 
        "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"> 
    <generatorConfiguration> 
      <!--          JDBC        ,            --> 
      <classPathEntry location="E:\Java\tool\maven_repository\mysql\mysql-connector-java\5.1.9\mysql-connector-java-5.1.9.jar"/> 
     
     
     
      <!--    table       ,targetRuntime      MyBatis3     --> 
      <context id="tables" targetRuntime="MyBatis3"> 
        <!--       ,            ,        --> 
        <commentGenerator> 
          <property name="suppressAllComments" value="true"/> 
        </commentGenerator> 
        <!--           --> 
        <jdbcConnection driverClass="com.mysql.jdbc.Driver" 
                connectionURL="jdbc:mysql://localhost:3306/springboot" 
                userId="root" 
                password="123456"> 
        </jdbcConnection> 
     
     
     
     
        <!--    model  ,targetPackage    model     , targetProject    
            model    IDEA        --> 
        <javaModelGenerator targetPackage="com.md.springboot.model" 
                  targetProject="src/main/java"> 
          <property name="enableSubPackages" value="false"/> 
          <property name="trimStrings" value="false"/> 
        </javaModelGenerator> 
     
     
     
     
        <!--    MyBatis   Mapper.xml   ,targetPackage    mapper.xml     
          , targetProject       mapper.xml    IDEA         --> 
        <sqlMapGenerator targetPackage="com.md.springboot.mapper" 
                 targetProject="src/main/java"> 
          <property name="enableSubPackages" value="false"/> 
        </sqlMapGenerator> 
     
     
     
     
     
        <!--    MyBatis   Mapper      ,targetPackage    Mapper       
         , targetProject       Mapper      IDEA         --> 
        <javaClientGenerator type="XMLMAPPER" 
                   targetPackage="com.md.springboot.mapper" targetProject="src/main/java"> 
          <property name="enableSubPackages" value="false"/> 
        </javaClientGenerator> 
     
     
     
     
     
        <!--           Java     ,       table --> 
        <table tableName="t_student" domainObjectName="Student" 
            enableCountByExample="false" 
            enableUpdateByExample="false" 
            enableDeleteByExample="false" 
            enableSelectByExample="false" 
            selectByExampleQueryId="false"/> 
     
     
      </context> 
    </generatorConfiguration> 
    이때 잘못 보고 할 수 있 습 니 다.아래 와 같 습 니 다.

    이 럴 때 는 신경 쓰 지 않 아 도 되 고,프로젝트 도 정상적으로 운 행 될 것 이다.
    Spring Boot 이론+실전 시리즈 튜 토리 얼
    3.pom.xml 파일 에 my sql 역방향 프로젝트 의존 도 를 추가 합 니 다.
    
    <build> 
      <plugins> 
        <!--mybatis         --> 
        <plugin> 
          <groupId>org.mybatis.generator</groupId> 
          <artifactId>mybatis-generator-maven-plugin</artifactId> 
          <version>1.3.6</version> 
          <configuration> 
            <!--       --> 
            <configurationFile>GeneratorMapper.xml</configurationFile> 
            <verbose>true</verbose> 
            <overwrite>true</overwrite> 
          </configuration> 
        </plugin> 
      </plugins> 
    
    </build> 
    4.파일 생 성 을 더 블 클릭

    5.생 성 된 파일
    모델/student,실체 클래스 자동 생 성
    인터페이스
    Student Mapper.xml 데이터베이스 에 대한 구체 적 인 조작
    이렇게 하면 우리 가 사용 하기에 편리 하 니,구체 적 인 아래 에 상세 하 게 소개 하고,주석 을 주의 깊 게 보 세 요.

    Student
    
    package com.md.springboot.model; 
     
    public class Student { 
      private Integer id; 
     
      private String name; 
     
      private Integer age; 
     
      public Integer getId() { 
        return id; 
      } 
     
      public void setId(Integer id) { 
        this.id = id; 
      } 
     
      public String getName() { 
        return name; 
      } 
     
      public void setName(String name) { 
        this.name = name; 
      } 
     
      public Integer getAge() { 
        return age; 
      } 
     
      public void setAge(Integer age) { 
        this.age = age; 
      } 
    } 
    StudentMapper
    
    package com.md.springboot.mapper; 
     
    import com.md.springboot.model.Student; 
     
    public interface StudentMapper { 
      int deleteByPrimaryKey(Integer id); 
     
      int insert(Student record); 
     
      int insertSelective(Student record); 
     
      Student selectByPrimaryKey(Integer id); 
     
      int updateByPrimaryKeySelective(Student record); 
     
      int updateByPrimaryKey(Student record); 
    } 
    StudentMapper.xml
    
    <?xml version="1.0" encoding="UTF-8"?> 
    <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> 
    <mapper namespace="com.md.springboot.mapper.StudentMapper"> 
     
     
     <!-- 
                         
      user_name      userName 
      user_age      userAge 
     
     --> 
     <!-- 
                       ,  Mybatis              
                        
                ,              
     
     --> 
     
     <!-- 
      resultMap    
      1.                        ,       
      2.                  ,           
     --> 
     <resultMap id="BaseResultMap" type="com.md.springboot.model.Student"> 
      <!-- 
       id          ,result         
       column           
       property           
       jdbcType       
      --> 
      <id column="id" jdbcType="INTEGER" property="id" /> 
      <result column="name" jdbcType="VARCHAR" property="name" /> 
      <result column="age" jdbcType="INTEGER" property="age" /> 
     </resultMap> 
     
     
     <!--sql    ,       --> 
     <sql id="Base_Column_List"> 
      id, name, age 
     </sql> 
     
     <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap"> 
      select  
      <include refid="Base_Column_List" /> 
      from t_student 
      where id = #{id,jdbcType=INTEGER} 
     </select> 
     
     <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer"> 
      delete from t_student 
      where id = #{id,jdbcType=INTEGER} 
     </delete> 
     
     <insert id="insert" parameterType="com.md.springboot.model.Student"> 
      insert into t_student (id, name, age 
       ) 
      values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{age,jdbcType=INTEGER} 
       ) 
     </insert> 
     
     
     <!--  sql--> 
     <insert id="insertSelective" parameterType="com.md.springboot.model.Student"> 
      insert into t_student 
      <trim prefix="(" suffix=")" suffixOverrides=","> 
       <if test="id != null"> 
        id, 
       </if> 
       <if test="name != null"> 
        name, 
       </if> 
       <if test="age != null"> 
        age, 
       </if> 
      </trim> 
      <trim prefix="values (" suffix=")" suffixOverrides=","> 
       <if test="id != null"> 
        #{id,jdbcType=INTEGER}, 
       </if> 
       <if test="name != null"> 
        #{name,jdbcType=VARCHAR}, 
       </if> 
       <if test="age != null"> 
        #{age,jdbcType=INTEGER}, 
       </if> 
      </trim> 
     </insert> 
     
     
     <update id="updateByPrimaryKeySelective" parameterType="com.md.springboot.model.Student"> 
      update t_student 
      <set> 
       <if test="name != null"> 
        name = #{name,jdbcType=VARCHAR}, 
       </if> 
       <if test="age != null"> 
        age = #{age,jdbcType=INTEGER}, 
       </if> 
      </set> 
      where id = #{id,jdbcType=INTEGER} 
     </update> 
     
     <update id="updateByPrimaryKey" parameterType="com.md.springboot.model.Student"> 
      update t_student 
      set name = #{name,jdbcType=VARCHAR}, 
       age = #{age,jdbcType=INTEGER} 
      where id = #{id,jdbcType=INTEGER} 
     </update> 
    </mapper> 
    이상 은 Spring Boot Mybatis 를 사용 하여 역방향 공 사 를 하 는 절차 에 대한 상세 한 내용 입 니 다.Spring Boot Mybatis 의 역방향 공사 에 관 한 자 료 는 우리 의 다른 관련 글 을 주목 하 세 요!

    좋은 웹페이지 즐겨찾기