Spring Boot Mybatis 를 사용 하여 역방향 공 사 를 하 는 절차
2.프로젝트 및 표 의 상황 에 따라 Generator Mapper.xml 설정 을 수정 합 니 다.
주로 주석 에 따라 자신의 내용 을 수정 합 니 다.
<?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 의 역방향 공사 에 관 한 자 료 는 우리 의 다른 관련 글 을 주목 하 세 요!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
[MeU] Hashtag 기능 개발➡️ 기존 Tag 테이블에 존재하지 않는 해시태그라면 Tag , tagPostMapping 테이블에 모두 추가 ➡️ 기존에 존재하는 해시태그라면, tagPostMapping 테이블에만 추가 이후에 개발할 태그 기반 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.