diff --git a/share_project/src/main/java/com/share/controller/DemandProjectController.java b/share_project/src/main/java/com/share/controller/DemandProjectController.java index 7c51b44d2c30c0aed94e746ca78a8d9fc848639c..3fd16ce5b948c81d4e3bc35cf6435e74935f4739 100644 --- a/share_project/src/main/java/com/share/controller/DemandProjectController.java +++ b/share_project/src/main/java/com/share/controller/DemandProjectController.java @@ -3,10 +3,13 @@ package com.share.controller; import com.share.domain.DemandProject; import com.share.domain.ResultInfo; import com.share.service.DemandProjectService; +import com.share.service.ProjectShowService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; +import javax.annotation.Resource; + /** * @author 谢佳豪 * @data 2020/11/24 - 20:12 @@ -19,6 +22,15 @@ public class DemandProjectController { private DemandProjectService demandProjectService; + private ProjectShowService projectShowService; + + + + @Resource(name = "demandProjectShowService") + public void setProjectShowService(ProjectShowService projectShowService) { + this.projectShowService = projectShowService; + } + @Autowired public void setDemandProjectService(DemandProjectService demandProjectService) { this.demandProjectService = demandProjectService; @@ -35,4 +47,9 @@ public class DemandProjectController { return demandProjectService.addDemandProject(demandProject, operation); } + @GetMapping("/project") + public ResultInfo selectProject(String projectName, String type, int page){ + return projectShowService.getProjectsByType(projectName, type, page); + } + } diff --git a/share_project/src/main/java/com/share/controller/TestController.java b/share_project/src/main/java/com/share/controller/TestController.java index fa36e014c66cba23154b753f5f83bd05b58f6a5c..42df09ab1e9720ce5434fcf42def29c0f54d3042 100644 --- a/share_project/src/main/java/com/share/controller/TestController.java +++ b/share_project/src/main/java/com/share/controller/TestController.java @@ -29,8 +29,8 @@ public class TestController { @RequestMapping("/1") @ResponseBody - public ResultInfo test(){ - return projectShowService.getProjectsByType("美工", 1); + public ResultInfo test(String projectName, String type, int page){ + return projectShowService.getProjectsByType(projectName, type, page); } diff --git a/share_project/src/main/java/com/share/mapper/DemandProjectMapper.java b/share_project/src/main/java/com/share/mapper/DemandProjectMapper.java index 8685c5f50e6e97585d7bc77e21758cc1852e4c92..43f28c0075a495465ec37b628ce0eee343bfe490 100644 --- a/share_project/src/main/java/com/share/mapper/DemandProjectMapper.java +++ b/share_project/src/main/java/com/share/mapper/DemandProjectMapper.java @@ -1,6 +1,7 @@ package com.share.mapper; import com.share.domain.DemandProject; +import com.share.vo.DemandProjectResponse; import com.share.vo.UserProjectListData; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; @@ -49,10 +50,19 @@ public interface DemandProjectMapper { /** - * 通过项目类型获取项目列表 - * @param type - * @param page - * @return + * 根据条件进行分页查询 + * @param projectName 项目名称,也可以为缩写 + * @param type 项目类型 + * @param page 分页查询出来的页数 + * @return 项目基本信息列表 + */ + List selectProjectByCondition(String projectName, String type, Integer page); + + /** + * 根据条件查询出项目总条数 + * @param projectName 项目名称,模糊查询的参数 + * @param type 项目类型 + * @return 查询出来的项目总数 */ - List selectProjectByType(String type, int page); + Integer countProjectByCondition(@Param("projectName") String projectName, @Param("type") String type); } diff --git a/share_project/src/main/java/com/share/service/ProjectShowService.java b/share_project/src/main/java/com/share/service/ProjectShowService.java index 7e05fbbe22e6a6391795d36cd509768055a84816..f6d0dc82f975c06be31a1f29dd75d08916d62017 100644 --- a/share_project/src/main/java/com/share/service/ProjectShowService.java +++ b/share_project/src/main/java/com/share/service/ProjectShowService.java @@ -15,9 +15,10 @@ public interface ProjectShowService { * 通过项目类型获取相应的项目列表 * @param type 项目类型 * @param page 页数 + * @param projectName 项目名称 * @return */ - ResultInfo getProjectsByType(@Param("type") String type, @Param("page") int page); + ResultInfo getProjectsByType(String projectName, String type, int page); } diff --git a/share_project/src/main/java/com/share/service/impl/DemandProjectShowServiceImpl.java b/share_project/src/main/java/com/share/service/impl/DemandProjectShowServiceImpl.java index cca22f10b406b5fb3163f96487219be4049f7cdc..3d65c96256e53624b8860d030dbb51bdb98fb5e4 100644 --- a/share_project/src/main/java/com/share/service/impl/DemandProjectShowServiceImpl.java +++ b/share_project/src/main/java/com/share/service/impl/DemandProjectShowServiceImpl.java @@ -1,12 +1,16 @@ package com.share.service.impl; import com.share.domain.ResultInfo; -import com.share.domain.SkillProject; import com.share.mapper.DemandProjectMapper; import com.share.service.ProjectShowService; +import com.share.vo.DemandProjectResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + /** * Demo Class * @@ -25,7 +29,26 @@ public class DemandProjectShowServiceImpl implements ProjectShowService { } @Override - public ResultInfo getProjectsByType(String type, int page) { - return ResultInfo.successInfo("成功", demandProjectMapper.selectProjectByType(type, (page - 1) * 20)); + public ResultInfo getProjectsByType(String projectName, String type, int page) { + int totalCount = demandProjectMapper.countProjectByCondition(projectName, type); + int totalPage; + //计算总页数和项目的总条数 + if (totalCount % 20 == 0){ + totalPage = totalCount / 20; + }else { + totalPage = totalCount / 20 + 1; + } + + if (page > totalPage || page <= 0){ + //如果提供的page参数越界,直接返回结果 + return ResultInfo.failInfo("页数错误"); + } + List responseList = demandProjectMapper.selectProjectByCondition(projectName, type, (page - 1) * 20); + //将数据存入hash表中 + Map resultMap = new HashMap<>(); + resultMap.put("totalCount", totalCount); + resultMap.put("totalPage", totalPage); + resultMap.put("result", responseList); + return ResultInfo.successInfo("success", resultMap); } } diff --git a/share_project/src/main/java/com/share/vo/DemandProjectResponse.java b/share_project/src/main/java/com/share/vo/DemandProjectResponse.java new file mode 100644 index 0000000000000000000000000000000000000000..b49c037beccd267c97df6d4c1e55914c58b3c6c8 --- /dev/null +++ b/share_project/src/main/java/com/share/vo/DemandProjectResponse.java @@ -0,0 +1,125 @@ +package com.share.vo; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +import java.io.Serializable; + +/** + * Demo Class + * + * @author 古市 + * @date 2020-12-06 16:55 + **/ +@JsonIgnoreProperties(value = { "handler" }) +public class DemandProjectResponse implements Serializable { + /** + * 项目编号 + */ + private Integer id; + /** + * 项目名称 + */ + private String projectName; + /** + * 项目描述 + */ + private String projectDesc; + /** + * 价钱 + */ + private Float price; + /** + * 地址 + */ + private String address; + /** + * 所需技能 + */ + private String skill; + /** + * 用户名 + */ + private String username; + /** + * 电话 + */ + private String telephone; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getProjectName() { + return projectName; + } + + public void setProjectName(String projectName) { + this.projectName = projectName; + } + + public String getProjectDesc() { + return projectDesc; + } + + public void setProjectDesc(String projectDesc) { + this.projectDesc = projectDesc; + } + + public Float getPrice() { + return price; + } + + public void setPrice(Float price) { + this.price = price; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getSkill() { + return skill; + } + + public void setSkill(String skill) { + this.skill = skill; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getTelephone() { + return telephone; + } + + public void setTelephone(String telephone) { + this.telephone = telephone; + } + + @Override + public String toString() { + return "DemandProjectResponse{" + + "id=" + id + + ", projectName='" + projectName + '\'' + + ", projectDesc='" + projectDesc + '\'' + + ", price=" + price + + ", address='" + address + '\'' + + ", skill='" + skill + '\'' + + ", username='" + username + '\'' + + ", telephone='" + telephone + '\'' + + '}'; + } +} diff --git a/share_project/src/main/resources/mapper/DemandProjectMapper.xml b/share_project/src/main/resources/mapper/DemandProjectMapper.xml index b710e988fac57c5256f81f99783e962569568493..91a21706356b2be696b59d22b1f1781f126b7f7a 100644 --- a/share_project/src/main/resources/mapper/DemandProjectMapper.xml +++ b/share_project/src/main/resources/mapper/DemandProjectMapper.xml @@ -4,6 +4,7 @@ "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> + @@ -19,6 +20,19 @@ + + + + + + + + + + + + + insert into demand_project @@ -84,8 +98,31 @@ where publisher = #{username} and id = #{id}; - + select id,project_name, price, skill, project_desc, address from demand_project + + + and type = #{type} + + + and project_name like concat('%',#{projectName},'%') + + + limit #{page}, 20 + + + + \ No newline at end of file diff --git a/share_project/src/main/resources/mapper/UserDemandProjectMapper.xml b/share_project/src/main/resources/mapper/UserDemandProjectMapper.xml index 056cc2e9e51b809e31db1b30581b2d84fc69dec2..3bea2db451e246bc7337b90f87adb3923932718f 100644 --- a/share_project/src/main/resources/mapper/UserDemandProjectMapper.xml +++ b/share_project/src/main/resources/mapper/UserDemandProjectMapper.xml @@ -20,4 +20,14 @@ update user_demand_project set status = #{status} where project_id = #{id}; + + + + + + \ No newline at end of file