SQL语句修改为xml

master
yang.yongquan 2022-07-06 11:22:48 +08:00
parent dc315eeca7
commit 58e0701d07
4 changed files with 27 additions and 31 deletions

View File

@ -1,5 +1,8 @@
package cn.edu.hfut.rmdjzz.projectmanagement.entity.query;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import lombok.AllArgsConstructor;
import lombok.Data;
@ -12,6 +15,7 @@ import java.time.LocalDate;
@Data
@AllArgsConstructor
public class ResultProject {
@TableId
Integer projectId;
String projectName;
Integer projectCreator;

View File

@ -23,35 +23,5 @@ public interface ProjectMapper extends BaseMapper<Project> {
""")
Long findProjectCount(@Param("id") Integer staffId);
@Select("""
SELECT * FROM
(SELECT project_id,
project_name,
contract_amount,
project_importance,
project_creator,
pt1.project_class_name as project_class_name,
pt2.project_class_name as project_subclass_name,
is_completed,
is_deleted,
project_closed_date
FROM project join project_type pt1 on project.project_class_id = pt1.project_class_id
join project_type pt2 on project.project_subclass_id = pt2.project_class_id
WHERE project_id IN (SELECT DISTINCT project_id FROM project_group WHERE staff_id = #{id})) AS T
${ew.customSqlSegment}
""")
@Results({
@Result(column = "project_id", property = "projectId", id = true),
@Result(column = "project_name", property = "projectName"),
@Result(column = "contract_amount", property = "contractAmount"),
@Result(column = "project_importance", property = "projectImportance"),
@Result(column = "project_class_name", property = "projectClassName"),
@Result(column = "project_subclass_name", property = "projectSubclassName"),
@Result(column = "project_class_name", property = "projectClassName"),
@Result(column = "is_completed", property = "completed"),
@Result(column = "is_deleted", property = "deleted"),
@Result(column = "project_closed_date", property = "projectClosedDate"),
@Result(column = "project_creator", property = "projectCreator")
})
IPage<ResultProject> findMyProject(IPage<ResultProject> pg, @Param("id") Integer staff_id, @Param(Constants.WRAPPER) Wrapper<Project> wrapper);
}

View File

@ -20,6 +20,7 @@ spring:
pathmatch:
matching-strategy: ant_path_matcher
mybatis-plus:
mapper-locations: classpath:mapper/*.xml
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
server:
@ -30,4 +31,4 @@ server:
encoding:
charset: UTF-8
force: true
enabled: true
enabled: true

View File

@ -0,0 +1,21 @@
<?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="cn.edu.hfut.rmdjzz.projectmanagement.mapper.ProjectMapper">
<select id="findMyProject" resultType="cn.edu.hfut.rmdjzz.projectmanagement.entity.query.ResultProject">
SELECT * FROM
(SELECT project_id,
project_name,
contract_amount,
project_importance,
project_creator,
pt1.project_class_name as project_class_name,
pt2.project_class_name as project_subclass_name,
is_completed as completed,
is_deleted as deleted,
project_closed_date
FROM project join project_type pt1 on project.project_class_id = pt1.project_class_id
join project_type pt2 on project.project_subclass_id = pt2.project_class_id
WHERE project_id IN (SELECT DISTINCT project_id FROM project_group WHERE staff_id = #{id})) AS T
${ew.customSqlSegment}
</select>
</mapper>