feat:把单词导入到数据库

This commit is contained in:
lbw
2025-12-10 13:49:21 +08:00
parent 8d1e2a5b75
commit 81f44376c5
9 changed files with 326 additions and 1 deletions

View File

@@ -75,6 +75,21 @@
<artifactId>commons-pool2</artifactId> <artifactId>commons-pool2</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@@ -0,0 +1,37 @@
package com.yinlihupo.enlish.service.domain.dataobject;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.time.LocalDateTime;
import java.util.Date;
@AllArgsConstructor
@NoArgsConstructor
@Data
@Builder
public class UnitDO {
/**
* 主键
*/
private Integer id;
/**
* 年级/单元
*/
private String title;
/**
* 版本
*/
private String version;
/**
* 创建时间
*/
private LocalDateTime createAt;
}

View File

@@ -0,0 +1,23 @@
package com.yinlihupo.enlish.service.domain.dataobject;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@AllArgsConstructor
@NoArgsConstructor
@Data
@Builder
public class VocabularyBankDO {
private Integer id;
private String word;
private String definition;
private String pronunciation;
private Integer unitId;
}

View File

@@ -0,0 +1,21 @@
package com.yinlihupo.enlish.service.domain.mapper;
import com.yinlihupo.enlish.service.domain.dataobject.UnitDO;
public interface UnitDOMapper {
int deleteByPrimaryKey(Integer id);
// 插入并返回 id
int insert(UnitDO record);
// 插入并返回 id
int insertSelective(UnitDO record);
UnitDO selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(UnitDO record);
int updateByPrimaryKey(UnitDO record);
UnitDO selectByTitle(String title);
}

View File

@@ -0,0 +1,17 @@
package com.yinlihupo.enlish.service.domain.mapper;
import com.yinlihupo.enlish.service.domain.dataobject.VocabularyBankDO;
public interface VocabularyBankDOMapper {
int deleteByPrimaryKey(Integer id);
int insert(VocabularyBankDO record);
int insertSelective(VocabularyBankDO record);
VocabularyBankDO selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(VocabularyBankDO record);
int updateByPrimaryKey(VocabularyBankDO record);
}

View File

@@ -45,7 +45,7 @@
targetProject="src/main/java"/> targetProject="src/main/java"/>
<!-- 需要生成的表-实体类 --> <!-- 需要生成的表-实体类 -->
<table tableName="class" domainObjectName="ClassDO" <table tableName="unit" domainObjectName="UnitDO"
enableCountByExample="false" enableCountByExample="false"
enableUpdateByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableDeleteByExample="false"

View File

@@ -0,0 +1,94 @@
<?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.yinlihupo.enlish.service.domain.mapper.UnitDOMapper">
<resultMap id="BaseResultMap" type="com.yinlihupo.enlish.service.domain.dataobject.UnitDO">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="title" jdbcType="VARCHAR" property="title" />
<result column="version" jdbcType="VARCHAR" property="version" />
<result column="create_at" jdbcType="TIMESTAMP" property="createAt" />
</resultMap>
<sql id="Base_Column_List">
id, title, version, create_at
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from unit
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from unit
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.yinlihupo.enlish.service.domain.dataobject.UnitDO" useGeneratedKeys="true" keyProperty="id">
insert into unit (title, version, create_at)
values (#{title,jdbcType=VARCHAR}, #{version,jdbcType=VARCHAR}, #{createAt,jdbcType=TIMESTAMP})
</insert>
<insert id="insertSelective" parameterType="com.yinlihupo.enlish.service.domain.dataobject.UnitDO" useGeneratedKeys="true" keyProperty="id">
insert into unit
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="title != null">
title,
</if>
<if test="version != null">
version,
</if>
<if test="createAt != null">
create_at,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=INTEGER},
</if>
<if test="title != null">
#{title,jdbcType=VARCHAR},
</if>
<if test="version != null">
#{version,jdbcType=VARCHAR},
</if>
<if test="createAt != null">
#{createAt,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.yinlihupo.enlish.service.domain.dataobject.UnitDO">
update unit
<set>
<if test="title != null">
title = #{title,jdbcType=VARCHAR},
</if>
<if test="version != null">
version = #{version,jdbcType=VARCHAR},
</if>
<if test="createAt != null">
create_at = #{createAt,jdbcType=TIMESTAMP},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.yinlihupo.enlish.service.domain.dataobject.UnitDO">
update unit
set title = #{title,jdbcType=VARCHAR},
version = #{version,jdbcType=VARCHAR},
create_at = #{createAt,jdbcType=TIMESTAMP}
where id = #{id,jdbcType=INTEGER}
</update>
<select id="selectByTitle" resultMap="BaseResultMap">
select *
from unit
where title = #{title}
</select>
</mapper>

View File

@@ -0,0 +1,100 @@
<?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.yinlihupo.enlish.service.domain.mapper.VocabularyBankDOMapper">
<resultMap id="BaseResultMap" type="com.yinlihupo.enlish.service.domain.dataobject.VocabularyBankDO">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="word" jdbcType="VARCHAR" property="word" />
<result column="definition" jdbcType="VARCHAR" property="definition" />
<result column="pronunciation" jdbcType="VARCHAR" property="pronunciation" />
<result column="unit_id" jdbcType="INTEGER" property="unitId" />
</resultMap>
<sql id="Base_Column_List">
id, word, `definition`, pronunciation, unit_id
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from vocabulary_bank
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from vocabulary_bank
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.yinlihupo.enlish.service.domain.dataobject.VocabularyBankDO">
insert into vocabulary_bank (id, word, `definition`, pronunciation, unit_id)
values (#{id,jdbcType=INTEGER}, #{word,jdbcType=VARCHAR}, #{definition,jdbcType=VARCHAR},
#{pronunciation,jdbcType=VARCHAR}, #{unitId,jdbcType=INTEGER})
</insert>
<insert id="insertSelective" parameterType="com.yinlihupo.enlish.service.domain.dataobject.VocabularyBankDO">
insert into vocabulary_bank
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="word != null">
word,
</if>
<if test="definition != null">
`definition`,
</if>
<if test="pronunciation != null">
pronunciation,
</if>
<if test="unitId != null">
unit_id,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=INTEGER},
</if>
<if test="word != null">
#{word,jdbcType=VARCHAR},
</if>
<if test="definition != null">
#{definition,jdbcType=VARCHAR},
</if>
<if test="pronunciation != null">
#{pronunciation,jdbcType=VARCHAR},
</if>
<if test="unitId != null">
#{unitId,jdbcType=INTEGER},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.yinlihupo.enlish.service.domain.dataobject.VocabularyBankDO">
update vocabulary_bank
<set>
<if test="word != null">
word = #{word,jdbcType=VARCHAR},
</if>
<if test="definition != null">
`definition` = #{definition,jdbcType=VARCHAR},
</if>
<if test="pronunciation != null">
pronunciation = #{pronunciation,jdbcType=VARCHAR},
</if>
<if test="unitId != null">
unit_id = #{unitId,jdbcType=INTEGER},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.yinlihupo.enlish.service.domain.dataobject.VocabularyBankDO">
update vocabulary_bank
set word = #{word,jdbcType=VARCHAR},
`definition` = #{definition,jdbcType=VARCHAR},
pronunciation = #{pronunciation,jdbcType=VARCHAR},
unit_id = #{unitId,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>

18
pom.xml
View File

@@ -85,6 +85,24 @@
<version>${revision}</version> <version>${revision}</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>5.2.3</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.2.3</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.20.0</version>
</dependency>
<!-- 避免编写那些冗余的 Java 样板式代码,如 get、set 等 --> <!-- 避免编写那些冗余的 Java 样板式代码,如 get、set 等 -->
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>