Explorar el Código

mybatisplus的xml文件映射

yuchengwei hace 5 meses
padre
commit
5679ac05b4

+ 2 - 1
src/main/java/com/qizhen/healsphere/config/MysqlConfig.java

@@ -8,6 +8,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
 import org.springframework.boot.jdbc.DataSourceBuilder;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
+import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
 
 import javax.sql.DataSource;
 
@@ -24,7 +25,7 @@ public class MysqlConfig {
     public SqlSessionFactory sqlSessionFactory(@Qualifier("dataSource") DataSource dataSource) throws Exception {
         MybatisSqlSessionFactoryBean sqlSessionFactoryBean = new MybatisSqlSessionFactoryBean();
         sqlSessionFactoryBean.setDataSource(dataSource);
-        
+        sqlSessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapper/mysql/*.xml"));
         // 添加 MyBatis 配置
         MybatisConfiguration configuration = new MybatisConfiguration();
         configuration.setMapUnderscoreToCamelCase(true);

+ 15 - 87
src/main/resources/mapper/mysql/KgCountInfoMapper.xml

@@ -1,88 +1,16 @@
-<!--<?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.qizhen.healsphere.repository.mapper.KgCountInfoMapper">-->
+<?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.qizhen.healsphere.repository.mapper.KgCountInfoMapper">
 
-<!--    &lt;!&ndash; 通用查询映射结果 &ndash;&gt;-->
-<!--    <resultMap id="BaseResultMap" type="com.qizhen.healsphere.repository.mapper.entity.KgCountInfo">-->
-<!--        <id column="id" property="id" />-->
-<!--        <result column="gmt_create" property="gmtCreate" />-->
-<!--        <result column="gmt_modified" property="gmtModified" />-->
-<!--        <result column="node_type" property="nodeType" />-->
-<!--        <result column="node_num" property="nodeNum" />-->
-<!--        <result column="node_prop_num" property="nodePropNum" />-->
-<!--        <result column="relation_type" property="relationType" />-->
-<!--        <result column="relation_num" property="relationNum" />-->
-<!--    </resultMap>-->
-
-<!--    <select id="getCountList" resultMap="BaseResultMap">-->
-<!--        select * from kg_count_info limit #{pageSize} offset #{offset}-->
-<!--    </select>-->
-
-<!--    <select id="count" resultType="java.lang.Integer">-->
-<!--        select count(*) from kg_count_info-->
-<!--    </select>-->
-
-<!--    &lt;!&ndash; 按照节点类型统计详细信息 &ndash;&gt;-->
-<!--    <select id="calculateDetailInfo" resultMap="BaseResultMap">-->
-<!--        SELECT -->
-<!--            n.category as node_type,-->
-<!--            COUNT(DISTINCT n.id) as node_num,-->
-<!--            COALESCE(SUM(prop_counts.prop_num), 0) as node_prop_num,-->
-<!--            COUNT(DISTINCT edge_counts.type) as relation_type,-->
-<!--            COALESCE(SUM(edge_counts.relation_count), 0) as relation_num-->
-<!--        FROM kg_nodes n-->
-<!--        LEFT JOIN (-->
-<!--            SELECT -->
-<!--                ref_id,-->
-<!--                COUNT(*) as prop_num-->
-<!--            FROM kg_props-->
-<!--            GROUP BY ref_id-->
-<!--        ) prop_counts ON n.id = prop_counts.ref_id-->
-<!--        LEFT JOIN (-->
-<!--            SELECT -->
-<!--                src_id as node_id,-->
-<!--                name as type,-->
-<!--                COUNT(*) as relation_count-->
-<!--            FROM kg_edges-->
-<!--            GROUP BY src_id, name-->
-<!--            UNION ALL-->
-<!--            SELECT -->
-<!--                dest_id as node_id,-->
-<!--                name as type,-->
-<!--                COUNT(*) as relation_count-->
-<!--            FROM kg_edges-->
-<!--            GROUP BY dest_id, name-->
-<!--        ) edge_counts ON n.id = edge_counts.node_id-->
-<!--        GROUP BY n.category-->
-<!--    </select>-->
-
-<!--    &lt;!&ndash; 清空统计表 &ndash;&gt;-->
-<!--    <delete id="clearTable">-->
-<!--        DELETE FROM kg_count_info-->
-<!--    </delete>-->
-
-<!--    &lt;!&ndash; 批量插入统计数据 &ndash;&gt;-->
-<!--    <insert id="batchInsert" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id">-->
-<!--        INSERT INTO kg_count_info (-->
-<!--            gmt_create,-->
-<!--            gmt_modified,-->
-<!--            node_type,-->
-<!--            node_num,-->
-<!--            node_prop_num,-->
-<!--            relation_type,-->
-<!--            relation_num-->
-<!--        ) VALUES -->
-<!--        <foreach collection="list" item="item" separator=",">-->
-<!--            (-->
-<!--                now(),-->
-<!--                now(),-->
-<!--                #{item.nodeType},-->
-<!--                #{item.nodeNum},-->
-<!--                #{item.nodePropNum},-->
-<!--                #{item.relationType},-->
-<!--                #{item.relationNum}-->
-<!--            )-->
-<!--        </foreach>-->
-<!--    </insert>-->
-
-<!--</mapper>-->
+    <!-- 通用查询映射结果 -->
+    <resultMap id="BaseResultMap" type="com.qizhen.healsphere.repository.mapper.entity.KgCountInfo">
+        <id column="id" property="id" />
+        <result column="gmt_create" property="gmtCreate" />
+        <result column="gmt_modified" property="gmtModified" />
+        <result column="node_type" property="nodeType" />
+        <result column="node_num" property="nodeNum" />
+        <result column="node_prop_num" property="nodePropNum" />
+        <result column="relation_type" property="relationType" />
+        <result column="relation_num" property="relationNum" />
+    </resultMap>
+</mapper>

+ 15 - 80
src/main/resources/mapper/mysql/KgCountTotalInfoMapper.xml

@@ -1,81 +1,16 @@
-<!--<?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.qizhen.healsphere.repository.mapper.KgCountTotalInfoMapper">-->
+<?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.qizhen.healsphere.repository.mapper.KgCountTotalInfoMapper">
 
-<!--    &lt;!&ndash; 通用查询映射结果 &ndash;&gt;-->
-<!--    <resultMap id="BaseResultMap" type="com.qizhen.healsphere.repository.mapper.entity.KgCountTotalInfo">-->
-<!--        <id column="id" property="id" />-->
-<!--        <result column="gmt_create" property="gmtCreate" />-->
-<!--        <result column="gmt_modified" property="gmtModified" />-->
-<!--        <result column="node_type_num" property="nodeTypeNum" />-->
-<!--        <result column="node_num" property="nodeNum" />-->
-<!--        <result column="node_prop_num" property="nodePropNum" />-->
-<!--        <result column="relation_type_num" property="relationTypeNum" />-->
-<!--        <result column="relation_num" property="relationNum" />-->
-<!--    </resultMap>-->
-
-<!--    <select id="getCountTotalInfo" resultMap="BaseResultMap">-->
-<!--        select * from kg_count_total_info limit 1-->
-<!--    </select>-->
-
-<!--    <insert id="save" parameterType="com.qizhen.healsphere.repository.mapper.entity.KgCountTotalInfo" -->
-<!--            useGeneratedKeys="true" keyProperty="id">-->
-<!--        insert into kg_count_total_info (-->
-<!--            id,-->
-<!--            gmt_create,-->
-<!--            gmt_modified,-->
-<!--            node_type_num,-->
-<!--            node_num,-->
-<!--            node_prop_num,-->
-<!--            relation_type_num,-->
-<!--            relation_num-->
-<!--        ) values (-->
-<!--            1,  &lt;!&ndash; 由于只有一条记录,直接使用固定值 1 &ndash;&gt;-->
-<!--            now(),-->
-<!--            now(),-->
-<!--            #{nodeTypeNum},-->
-<!--            #{nodeNum},-->
-<!--            #{nodePropNum},-->
-<!--            #{relationTypeNum},-->
-<!--            #{relationNum}-->
-<!--        )-->
-<!--    </insert>-->
-
-<!--    <update id="update" parameterType="com.qizhen.healsphere.repository.mapper.entity.KgCountTotalInfo">-->
-<!--        update kg_count_total_info-->
-<!--        set gmt_modified = now(),-->
-<!--            node_type_num = #{nodeTypeNum},-->
-<!--            node_num = #{nodeNum},-->
-<!--            node_prop_num = #{nodePropNum},-->
-<!--            relation_type_num = #{relationTypeNum},-->
-<!--            relation_num = #{relationNum}-->
-<!--        where id = #{id}-->
-<!--    </update>-->
-
-<!--    &lt;!&ndash; 统计所有节点和关系的汇总信息 &ndash;&gt;-->
-<!--    <select id="calculateTotalInfo" resultMap="BaseResultMap">-->
-<!--        SELECT -->
-<!--            t1.node_type_num,-->
-<!--            t1.node_num,-->
-<!--            t2.node_prop_num,-->
-<!--            t3.relation_type_num,-->
-<!--            t3.relation_num-->
-<!--        FROM (-->
-<!--            SELECT -->
-<!--                COUNT(DISTINCT category) as node_type_num,-->
-<!--                COUNT(*) as node_num -->
-<!--            FROM kg_nodes-->
-<!--        ) t1,-->
-<!--        (-->
-<!--            SELECT COUNT(*) as node_prop_num -->
-<!--            FROM kg_props-->
-<!--        ) t2,-->
-<!--        (-->
-<!--            SELECT -->
-<!--                COUNT(DISTINCT name) as relation_type_num,-->
-<!--                COUNT(*) as relation_num -->
-<!--            FROM kg_edges-->
-<!--        ) t3-->
-<!--    </select>-->
-
-<!--</mapper>-->
+    <!-- 通用查询映射结果 -->
+    <resultMap id="BaseResultMap" type="com.qizhen.healsphere.repository.mapper.entity.KgCountTotalInfo">
+        <id column="id" property="id" />
+        <result column="gmt_create" property="gmtCreate" />
+        <result column="gmt_modified" property="gmtModified" />
+        <result column="node_type_num" property="nodeTypeNum" />
+        <result column="node_num" property="nodeNum" />
+        <result column="node_prop_num" property="nodePropNum" />
+        <result column="relation_type_num" property="relationTypeNum" />
+        <result column="relation_num" property="relationNum" />
+    </resultMap>
+</mapper>

+ 1 - 1
src/main/resources/mapper/mysql/KgNodeMapper.xml

@@ -29,7 +29,7 @@
     </update>
     <!-- 根据ID查询 -->
     <select id="getKgNode" resultMap="BaseResultMap">
-        SELECT * FROM kg_node WHERE name = #{name} and category = #{category},
+        SELECT * FROM kg_nodes WHERE name = #{name} and category = #{category}
     </select>
 
     <!-- 根据ID查询 -->

+ 17 - 23
src/main/resources/mapper/mysql/PresetInfoMapper.xml

@@ -1,24 +1,18 @@
-<!--<?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.qizhen.healsphere.repository.mapper.PresetInfoMapper">-->
+<?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.qizhen.healsphere.repository.mapper.PresetInfoMapper">
 
-<!--    &lt;!&ndash; 通用查询映射结果 &ndash;&gt;-->
-<!--    <resultMap id="BaseResultMap" type="com.qizhen.healsphere.repository.mapper.entity.PresetInfo">-->
-<!--        <id column="id" property="id" />-->
-<!--        <result column="is_deleted" property="isDeleted" />-->
-<!--        <result column="gmt_create" property="gmtCreate" />-->
-<!--        <result column="gmt_modified" property="gmtModified" />-->
-<!--        <result column="creator" property="creator" />-->
-<!--        <result column="modifier" property="modifier" />-->
-<!--        <result column="type" property="type" />-->
-<!--        <result column="title" property="title" />-->
-<!--        <result column="content" property="content" />-->
-<!--        <result column="remark" property="remark" />-->
-<!--    </resultMap>-->
-
-<!--    <select id="getPresetInfoByType" resultMap="BaseResultMap" parameterType="java.lang.Integer">-->
-<!--        select * from ltkg_preset_info where type = #{type} and is_deleted = 'N' limit 1-->
-<!--    </select>-->
-
-
-<!--</mapper>-->
+    <!-- 通用查询映射结果 -->
+    <resultMap id="BaseResultMap" type="com.qizhen.healsphere.repository.mapper.entity.PresetInfo">
+        <id column="id" property="id" />
+        <result column="is_deleted" property="isDeleted" />
+        <result column="gmt_create" property="gmtCreate" />
+        <result column="gmt_modified" property="gmtModified" />
+        <result column="creator" property="creator" />
+        <result column="modifier" property="modifier" />
+        <result column="type" property="type" />
+        <result column="title" property="title" />
+        <result column="content" property="content" />
+        <result column="remark" property="remark" />
+    </resultMap>
+</mapper>