个人主页展示系统(springBoot)-no6-信息查询功能开发

文章目录


前言

今天要介绍信息的查询功能开发,包括用户信息的查询、教育信息的查询、工作经历信息的查询、技能信息的查询、特长信息的查询


一、实体类编写

增加一个实体类Information,用来存储查询的信息,类的内容如下:

@ApiModel(value = "用户信息实体类",description = "描述用户的所有信息")
@Data
@AllArgsConstructor
public class Information {
    @ApiModelProperty(value = "用户基本信息")
    private User user;
    @ApiModelProperty(value = "用户教育信息")
    private Education education;
    @ApiModelProperty(value = "用户工作信息")
    private Work work;
    @ApiModelProperty(value = "用户技能信息")
    private Skill skill;
    @ApiModelProperty(value = "用户特长信息")
    private Specialty specialty;
}

二、数据接口层编写

1.映射文件编写

在UserMapper映射文件中新增下列代码:

   <select id="selectUser" parameterType="Integer" resultType="com.personal.homepage.bean.User">
        select * from homepage_user where id=#{userid}
    </select>

在EducationMapper映射文件中新增下列代码:

   <select id="selectEduction" parameterType="Integer" resultType="com.personal.homepage.bean.Education">
        select * from homepage_edu where userid=#{userid} order by start
    </select>

在WorkMapper映射文件中新增下列代码:

  <select id="selectWork" parameterType="Integer" resultType="com.personal.homepage.bean.Work">
        select * from homepage_work where userid=#{userid} order by start
    </select>

在SkillMapper映射文件中新增下列代码:

 <select id="selectSkill" parameterType="Integer" resultType="com.personal.homepage.bean.Skill">
        select * from homepage_skill where userid=#{userid}
    </select>

在SpecialtyMapper映射文件中新增下列代码:

    <select id="selectSpecialty" parameterType="Integer" resultType="com.personal.homepage.bean.Specialty">
        select * from homepage_specialty where userid=#{userid}
    </select>

2.接口编写

按照上述的映射文件分别在dao的接口添加相应的方法即可。

三、服务层编写

在EducationServiceImpl中增加以下代码: 由于用户的教育信息可以多条,所以把用户的教育信息拼接在一起,类似于链表
 public Education select(int userid) {
        Education[] temp = educationDao.selectEduction(userid);
        Education education = null;
        if (temp.length>1){
            for (int i=1;i<temp.length;i++){
                education = new Education();
                education.setNextEducation(temp[i]);
            }
        }else  if (temp.length==1){
            education = new Education();
        }
        education.setId(temp[0].getId());
        education.setUserid(temp[0].getUserid());
        education.setStart(temp[0].getStart());
        education.setEnd(temp[0].getEnd());
        education.setSchool(temp[0].getSchool());
        education.setSchool(temp[0].getSchool());
        education.setMajor(temp[0].getMajor());
        education.setDescription(temp[0].getDescription());
        return education;
    }
同样地在WorkServiceImpl中增加以下代码:
  public Work select(int userid) {
        Work[] temp = workDao.selectWork(userid);
        Work work = null;
        if (temp.length>1){
            for (int i=1;i< temp.length;i++){
                work = new Work();
                work.setNextWork(temp[i]);
            }
        }else if (temp.length==1){
            work = new Work();
        }
        work.setId(temp[0].getId());
        work.setUserid(temp[0].getUserid());
        work.setStart(temp[0].getStart());
        work.setEnd(temp[0].getEnd());
        work.setCompany(temp[0].getCompany());
        work.setJob(temp[0].getJob());
        work.setDescription(temp[0].getDescription());
        return work;
    }
}
在SkillServiceImpl中增加以下代码:
 public Skill select(int userid) {
        return skillDao.selectSkill(userid);
    }
在SpecialtyServiceImpl中增加以下代码:
  public Specialty select(int userid) {
        Specialty[] temp = specialtyDao.selectSpecialty(userid);
        Specialty specialty = null;
        if (temp.length > 1) {
            for (int i = 1; i < temp.length; i++) {
                specialty = new Specialty();
                specialty.setNextSpecialty(temp[i]);
            }
        } else if (temp.length == 1) {
            specialty = new Specialty();
        }
        specialty.setId(temp[0].getId());
        specialty.setUserid(temp[0].getUserid());
        specialty.setName(temp[0].getName());
        specialty.setDescription(temp[0].getDescription());
        return specialty;
    }

在UserServiceImpl中增加以下代码:
    public User select(int userid) {
        return userDao.selectUser(userid);
    }

    public Result selectInformation(int userid) {
        User user = userDao.selectUser(userid);
        if (user == null){
            return new Result(0,"查询失败");
        }
        Education education = educationService.select(userid);
        Work work = workService.select(userid);
        Skill skill = skillService.select(userid);
        Specialty specialty = specialtyService.select(userid);
        Information information = new Information(user,education,work,skill,specialty);
        return new Result(1,"查询成功",information);

    }

四、控制器层编写

在UserController类中新增以下方法:

    @ApiResponses({
            @ApiResponse(code=1,message = "查询成功"),
            @ApiResponse(code = 0,message = "查询失败")
    })
    @ApiOperation(value = "查询用户所有信息",notes = "查询用户所有信息")
    @GetMapping("/selectInformation/{userid}")
    public Result selectInformation(@ApiParam("用户id") @PathVariable int userid){
        return  userService.selectInformation(userid);
    }

总结

至此后端的开发已经全部完成,项目已经上传到我的gitee:项目地址,其中homepage为后端代码,resume为前端的代码。在下一篇博客中我会介绍一下怎么安装项目

上一篇:# [USACO09OPEN]Work Scheduling 经典反悔贪心 ##


下一篇:《HF 设计模式》 C1 策略模式