修复了xml的mapper中不能使用mybatis-plus映射的问题

master
ArgonarioD 2022-07-06 14:48:15 +08:00
parent 17f516545b
commit c81065d93e
3 changed files with 27 additions and 4 deletions

View File

@ -1,6 +1,8 @@
package cn.edu.hfut.rmdjzz.projectmanagement.entity.query; 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.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
@ -12,6 +14,7 @@ import java.time.LocalDate;
*/ */
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@TableName(autoResultMap = true)
public class ResultProject { public class ResultProject {
@TableId @TableId
Integer projectId; Integer projectId;

View File

@ -1,7 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?> <?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"> <!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"> <mapper namespace="cn.edu.hfut.rmdjzz.projectmanagement.mapper.ProjectMapper">
<select id="findMyProject" resultType="cn.edu.hfut.rmdjzz.projectmanagement.entity.query.ResultProject"> <resultMap id="resultProject" type="cn.edu.hfut.rmdjzz.projectmanagement.entity.query.ResultProject">
<id property="projectId" column="project_id"/>
<result property="completed" column="is_completed"/>
<result property="deleted" column="is_deleted"/>
</resultMap>
<select id="findMyProject" resultMap="resultProject">
SELECT * SELECT *
FROM (SELECT project_id, FROM (SELECT project_id,
project_name, project_name,
@ -10,8 +16,8 @@
project_creator, project_creator,
pt1.project_class_name AS project_class_name, pt1.project_class_name AS project_class_name,
pt2.project_class_name AS project_subclass_name, pt2.project_class_name AS project_subclass_name,
is_completed AS completed, is_completed,
is_deleted AS deleted, is_deleted,
project_closed_date project_closed_date
FROM project FROM project
JOIN project_type pt1 ON project.project_class_id = pt1.project_class_id JOIN project_type pt1 ON project.project_class_id = pt1.project_class_id

View File

@ -1,11 +1,11 @@
package cn.edu.hfut.rmdjzz.projectmanagement; package cn.edu.hfut.rmdjzz.projectmanagement;
import cn.edu.hfut.rmdjzz.projectmanagement.entity.Project; import cn.edu.hfut.rmdjzz.projectmanagement.entity.Project;
import cn.edu.hfut.rmdjzz.projectmanagement.entity.Staff;
import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectService; import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectService;
import cn.edu.hfut.rmdjzz.projectmanagement.service.IStaffService; import cn.edu.hfut.rmdjzz.projectmanagement.service.IStaffService;
import cn.edu.hfut.rmdjzz.projectmanagement.service.impl.ProjectServiceImpl; import cn.edu.hfut.rmdjzz.projectmanagement.service.impl.ProjectServiceImpl;
import cn.edu.hfut.rmdjzz.projectmanagement.utils.WrapperUtils; import cn.edu.hfut.rmdjzz.projectmanagement.utils.WrapperUtils;
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.RequestPage;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -73,4 +73,18 @@ public class MybatisPlusTests {
System.out.println(objectMapper.writeValueAsString(((ProjectServiceImpl) projectService).getBaseMapper() System.out.println(objectMapper.writeValueAsString(((ProjectServiceImpl) projectService).getBaseMapper()
.findMyProject(new Page<>(1, 5), 1, Wrappers.query()))); .findMyProject(new Page<>(1, 5), 1, Wrappers.query())));
} }
@SneakyThrows
@Test
public void findProjectTest() {
RequestPage page = new RequestPage();
page.setPageCurrent(1);
page.setPageSize(5);
Map<String, Object> map = new HashMap<>();
map.put("completed", true);
System.out.println(objectMapper.writeValueAsString(projectService
.getOnePageProject("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJkdXJhdGlvbiI6MTgwMDAsInN0YWZmVXNlcm5hbWUiOiJtaWtlIiwiZXhwIjoxNjU3MDkzNTU1LCJpYXQiOjE2NTcwNzU1NTUsInN0YWZmSWQiOjF9.g8l01dnHglt223469Z03i9gqZL8P13Fo7KoaA1pf310",
page, map)));
}
} }