mirror of
https://github.com/zfile-dev/zfile.git
synced 2025-04-19 05:34:52 +00:00
切换 ORM 框架为 JPA, 数据库为 H2.
This commit is contained in:
27
pom.xml
27
pom.xml
@@ -18,7 +18,6 @@
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<mybatis.starter.version>1.3.2</mybatis.starter.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
@@ -34,6 +33,10 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-aop</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
@@ -113,9 +116,25 @@
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>${mybatis.starter.version}</version>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org</groupId>
|
||||
<artifactId>jaudiotagger</artifactId>
|
||||
<version>2.0.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.mpatric</groupId>
|
||||
<artifactId>mp3agic</artifactId>
|
||||
<version>0.9.1</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
package im.zhaojun.common.enums;
|
||||
|
||||
import org.apache.ibatis.type.BaseTypeHandler;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class StorageTypeEnumTypeHandler extends BaseTypeHandler<StorageTypeEnum>{
|
||||
|
||||
public StorageTypeEnumTypeHandler(Class<StorageTypeEnum> type) {
|
||||
if (type == null)
|
||||
throw new IllegalArgumentException("Type argument cannot be null");
|
||||
StorageTypeEnum[] enums = type.getEnumConstants();
|
||||
if (enums == null)
|
||||
throw new IllegalArgumentException(type.getSimpleName()
|
||||
+ " does not represent an enum type.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageTypeEnum getNullableResult(ResultSet rs, String columnName) throws SQLException {
|
||||
String i = rs.getString(columnName);
|
||||
if (rs.wasNull()) {
|
||||
return null;
|
||||
} else {
|
||||
return StorageTypeEnum.getEnum(i);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageTypeEnum getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
|
||||
String i = rs.getString(columnIndex);
|
||||
if (rs.wasNull()) {
|
||||
return null;
|
||||
} else {
|
||||
return StorageTypeEnum.getEnum(i);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageTypeEnum getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
|
||||
String i = cs.getString(columnIndex);
|
||||
if (cs.wasNull()) {
|
||||
return null;
|
||||
} else {
|
||||
return StorageTypeEnum.getEnum(i);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNonNullParameter(PreparedStatement ps, int i, StorageTypeEnum parameter, JdbcType jdbcType)
|
||||
throws SQLException {
|
||||
ps.setString(i, parameter.getKey());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
package im.zhaojun.common.enums;
|
||||
|
||||
import org.apache.ibatis.type.BaseTypeHandler;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class ViewModeEnumTypeHandler extends BaseTypeHandler<ViewModeEnum>{
|
||||
|
||||
public ViewModeEnumTypeHandler(Class<ViewModeEnum> type) {
|
||||
if (type == null)
|
||||
throw new IllegalArgumentException("Type argument cannot be null");
|
||||
ViewModeEnum[] enums = type.getEnumConstants();
|
||||
if (enums == null)
|
||||
throw new IllegalArgumentException(type.getSimpleName()
|
||||
+ " does not represent an enum type.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ViewModeEnum getNullableResult(ResultSet rs, String columnName) throws SQLException {
|
||||
String i = rs.getString(columnName);
|
||||
if (rs.wasNull()) {
|
||||
return null;
|
||||
} else {
|
||||
return ViewModeEnum.getEnum(i);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ViewModeEnum getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
|
||||
String i = rs.getString(columnIndex);
|
||||
if (rs.wasNull()) {
|
||||
return null;
|
||||
} else {
|
||||
return ViewModeEnum.getEnum(i);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ViewModeEnum getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
|
||||
String i = cs.getString(columnIndex);
|
||||
if (cs.wasNull()) {
|
||||
return null;
|
||||
} else {
|
||||
return ViewModeEnum.getEnum(i);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNonNullParameter(PreparedStatement ps, int i, ViewModeEnum parameter, JdbcType jdbcType)
|
||||
throws SQLException {
|
||||
ps.setString(i, parameter.getValue());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package im.zhaojun.common.mapper;
|
||||
|
||||
import im.zhaojun.common.enums.StorageTypeEnum;
|
||||
import im.zhaojun.common.model.StorageConfig;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface StorageConfigMapper {
|
||||
int deleteByPrimaryKey(Integer id);
|
||||
|
||||
int insert(StorageConfig record);
|
||||
|
||||
int insertSelective(StorageConfig record);
|
||||
|
||||
StorageConfig selectByPrimaryKey(Integer id);
|
||||
|
||||
int updateByPrimaryKeySelective(StorageConfig record);
|
||||
|
||||
int updateByPrimaryKey(StorageConfig record);
|
||||
|
||||
List<StorageConfig> selectStorageConfigByType(StorageTypeEnum type);
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package im.zhaojun.common.mapper;
|
||||
|
||||
import im.zhaojun.common.model.SystemConfig;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface SystemConfigMapper {
|
||||
|
||||
int insert(SystemConfig record);
|
||||
|
||||
int updateByPrimaryKeySelective(SystemConfig record);
|
||||
|
||||
int updateByPrimaryKey(SystemConfig record);
|
||||
|
||||
SystemConfig selectFirstConfig();
|
||||
}
|
||||
@@ -1,111 +0,0 @@
|
||||
<?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="im.zhaojun.common.mapper.StorageConfigMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="im.zhaojun.common.model.StorageConfig">
|
||||
<!--@mbg.generated-->
|
||||
<id column="id" jdbcType="INTEGER" property="id"/>
|
||||
<result column="type" jdbcType="LONGVARCHAR" property="type" javaType="im.zhaojun.common.enums.StorageTypeEnum"
|
||||
typeHandler="im.zhaojun.common.enums.StorageTypeEnumTypeHandler"/>
|
||||
<result column="key" jdbcType="LONGVARCHAR" property="key"/>
|
||||
<result column="title" jdbcType="LONGVARCHAR" property="title"/>
|
||||
<result column="value" jdbcType="LONGVARCHAR" property="value"/>
|
||||
</resultMap>
|
||||
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
<!--@mbg.generated-->
|
||||
id, "type", "key", title, "value"
|
||||
</sql>
|
||||
|
||||
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
|
||||
<!--@mbg.generated-->
|
||||
select
|
||||
<include refid="Base_Column_List"/>
|
||||
from storage_config
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</select>
|
||||
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
|
||||
<!--@mbg.generated-->
|
||||
delete from storage_config
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</delete>
|
||||
|
||||
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="im.zhaojun.common.model.StorageConfig"
|
||||
useGeneratedKeys="true">
|
||||
<!--@mbg.generated-->
|
||||
insert into storage_config ("key", "type", title,
|
||||
"value")
|
||||
values (#{key,jdbcType=LONGVARCHAR}, #{type,jdbcType=LONGVARCHAR}, #{title,jdbcType=LONGVARCHAR},
|
||||
#{value,jdbcType=LONGVARCHAR})
|
||||
</insert>
|
||||
|
||||
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="im.zhaojun.common.model.StorageConfig"
|
||||
useGeneratedKeys="true">
|
||||
<!--@mbg.generated-->
|
||||
insert into storage_config
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="key != null">
|
||||
"key",
|
||||
</if>
|
||||
<if test="type != null">
|
||||
"type",
|
||||
</if>
|
||||
<if test="title != null">
|
||||
title,
|
||||
</if>
|
||||
<if test="value != null">
|
||||
"value",
|
||||
</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="key != null">
|
||||
#{key,jdbcType=LONGVARCHAR},
|
||||
</if>
|
||||
<if test="type != null">
|
||||
#{type,jdbcType=LONGVARCHAR},
|
||||
</if>
|
||||
<if test="title != null">
|
||||
#{title,jdbcType=LONGVARCHAR},
|
||||
</if>
|
||||
<if test="value != null">
|
||||
#{value,jdbcType=LONGVARCHAR},
|
||||
</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateByPrimaryKeySelective" parameterType="im.zhaojun.common.model.StorageConfig">
|
||||
<!--@mbg.generated-->
|
||||
update storage_config
|
||||
<set>
|
||||
<if test="key != null">
|
||||
"key" = #{key,jdbcType=LONGVARCHAR},
|
||||
</if>
|
||||
<if test="type != null">
|
||||
"type" = #{type,jdbcType=LONGVARCHAR},
|
||||
</if>
|
||||
<if test="title != null">
|
||||
title = #{title,jdbcType=LONGVARCHAR},
|
||||
</if>
|
||||
<if test="value != null">
|
||||
"value" = #{value,jdbcType=LONGVARCHAR},
|
||||
</if>
|
||||
</set>
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</update>
|
||||
|
||||
<update id="updateByPrimaryKey" parameterType="im.zhaojun.common.model.StorageConfig">
|
||||
<!--@mbg.generated-->
|
||||
update storage_config
|
||||
set "key" = #{key,jdbcType=LONGVARCHAR},
|
||||
"type" = #{type,jdbcType=LONGVARCHAR},
|
||||
title = #{title,jdbcType=LONGVARCHAR},
|
||||
"value" = #{value,jdbcType=LONGVARCHAR}
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</update>
|
||||
|
||||
|
||||
<select id="selectStorageConfigByType" parameterType="im.zhaojun.common.enums.StorageTypeEnum" resultMap="BaseResultMap">
|
||||
select * from storage_config where `type` = #{type, typeHandler=im.zhaojun.common.enums.StorageTypeEnumTypeHandler}
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -1,77 +0,0 @@
|
||||
<?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="im.zhaojun.common.mapper.SystemConfigMapper">
|
||||
<resultMap id="BaseResultMap" type="im.zhaojun.common.model.SystemConfig">
|
||||
<!--@mbg.generated-->
|
||||
<id column="id" jdbcType="INTEGER" property="id"/>
|
||||
<result column="site_name" jdbcType="LONGVARCHAR" property="siteName"/>
|
||||
<result column="mode" jdbcType="LONGVARCHAR" property="mode" javaType="im.zhaojun.common.enums.ViewModeEnum"
|
||||
typeHandler="im.zhaojun.common.enums.ViewModeEnumTypeHandler"/>
|
||||
<result column="sidebarEnable" jdbcType="NUMERIC" property="sidebarEnable"/>
|
||||
<result column="infoEnable" jdbcType="NUMERIC" property="infoEnable"/>
|
||||
<result column="searchEnable" jdbcType="NUMERIC" property="searchEnable"/>
|
||||
<result column="searchIgnoreCase" jdbcType="NUMERIC" property="searchIgnoreCase"/>
|
||||
<result column="storageStrategy" jdbcType="LONGVARCHAR" property="storageStrategy" javaType="im.zhaojun.common.enums.StorageTypeEnum" typeHandler="im.zhaojun.common.enums.StorageTypeEnumTypeHandler"/>
|
||||
</resultMap>
|
||||
<sql id="Base_Column_List">
|
||||
<!--@mbg.generated-->
|
||||
id, site_name, "mode", sidebarEnable, infoEnable, searchEnable, searchIgnoreCase, storageStrategy
|
||||
</sql>
|
||||
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="im.zhaojun.common.model.SystemConfig"
|
||||
useGeneratedKeys="true">
|
||||
<!--@mbg.generated-->
|
||||
insert into system_config (site_name, "mode", sidebarEnable,
|
||||
infoEnable, searchEnable, searchIgnoreCase, storage_strategy, timeout
|
||||
)
|
||||
values (#{siteName,jdbcType=LONGVARCHAR}, #{mode,jdbcType=NUMERIC}, #{sidebarenable,jdbcType=NUMERIC},
|
||||
#{infoenable,jdbcType=NUMERIC}, #{searchenable,jdbcType=NUMERIC}, #{searchignorecase,jdbcType=NUMERIC},
|
||||
#{storageStrategy,jdbcType=LONGVARCHAR}
|
||||
)
|
||||
</insert>
|
||||
<update id="updateByPrimaryKeySelective" parameterType="im.zhaojun.common.model.SystemConfig">
|
||||
<!--@mbg.generated-->
|
||||
update system_config
|
||||
<set>
|
||||
<if test="siteName != null">
|
||||
site_name = #{siteName,jdbcType=LONGVARCHAR},
|
||||
</if>
|
||||
<if test="mode != null">
|
||||
"mode" = #{mode,jdbcType=NUMERIC},
|
||||
</if>
|
||||
<if test="sidebarenable != null">
|
||||
sidebarEnable = #{sidebarEnable,jdbcType=NUMERIC},
|
||||
</if>
|
||||
<if test="infoenable != null">
|
||||
infoEnable = #{infoEnable,jdbcType=NUMERIC},
|
||||
</if>
|
||||
<if test="searchenable != null">
|
||||
searchEnable = #{searchEnable,jdbcType=NUMERIC},
|
||||
</if>
|
||||
<if test="searchignorecase != null">
|
||||
searchIgnoreCase = #{searchIgnoreCase,jdbcType=NUMERIC},
|
||||
</if>
|
||||
<if test="storage_strategy != null">
|
||||
storageStrategy = #{storageStrategy,jdbcType=LONGVARCHAR},
|
||||
</if>
|
||||
</set>
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</update>
|
||||
<update id="updateByPrimaryKey" parameterType="im.zhaojun.common.model.SystemConfig">
|
||||
<!--@mbg.generated-->
|
||||
update system_config
|
||||
set site_name = #{siteName,jdbcType=LONGVARCHAR},
|
||||
"mode" = #{mode,jdbcType=NUMERIC},
|
||||
sidebarEnable = #{sidebarEnable,jdbcType=NUMERIC},
|
||||
infoEnable = #{infoEnable,jdbcType=NUMERIC},
|
||||
searchEnable = #{searchEnable,jdbcType=NUMERIC},
|
||||
searchIgnoreCase = #{searchIgnoreCase,jdbcType=NUMERIC},
|
||||
storageStrategy = #{storageStrategy,jdbcType=NUMERIC}
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</update>
|
||||
|
||||
<select id="selectFirstConfig" resultMap="BaseResultMap">
|
||||
select
|
||||
<include refid="Base_Column_List"/>
|
||||
from system_config limit 1
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user