本文主要是介绍十次方微服务项目实战05--招聘问答模块微服务开发及代码自动生成,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一、招聘微服务模块
1.1 原型
先来看一下页面原型,如图:
招聘微服务主要有两块:企业信息和招聘信息
两个大功能:推荐职位和最新职位
1.2 表结构分析
1.2.1 企业表
1.2.2 招聘信息表
1.3 代码生成
接下来使用开源代码生成器codeutil
来完成代码的生成
开源网址: https://gitee.com/chuanzhiliubei/codeutil
生成步骤:
- 使用代码生成器生成招聘微服务代码
tensquare_recruit
- 拷贝到当前工程,并在父工程引入
- 修改
Application
类名称为RecruitApplication
- 修改
application.yml
中的端口为9002
,url
为jdbc:mysql://127.0.0.1:3306/tensquare_recruit?characterEncoding=UTF8
- 使用
Postman
进行测试
1.4 热门企业列表
需求:查询企业表ishot字段为1的记录
1.4.1 EnterpriseDao新增方法定义
/*** 根据热门状态获取企业列表* @param ishot* @return*/public List<Enterprise> findByIshot(String ishot); // where ishot = ?
1.4.2 EnterpriseService新增方法
/*** 查询热门企业列表** @return*/public List<Enterprise> hotList() {return enterpriseDao.findByIshot("1");}
1.4.3 EnterpriseController新增方法
@RequestMapping(value = "/search/hotlist", method = RequestMethod.GET)
public Result hotList() {return Result.ok(enterpriseService.hotList());}
1.4.4 测试
访问如下网址进行测试:http://localhost:9002/enterprise/search/hotlist
1.5 推荐职位列表
需求:查询状态为2并以创建日期降序排序,查询前4条记录
1.5.1 RecruitDao新增方法定义
/*** 根据职位状态查询前4条记录,并以创建日期降序排序** @param state* @return*/List<Recruit> findTop4ByStateOrderByCreatetimeDesc(String state);// where state = ? order by createtime desc
1.5.2 RecruitService新增方法
public List<Recruit> findTop4ByStateOrderByCreatetimeDesc(String state) {return recruitDao.findTop4ByStateOrderByCreatetimeDesc(state);}
1.5.3 RecruitController新增方法
/*** 查询推荐职位列表** @return*/@RequestMapping(value = "/search/recommend", method = RequestMethod.GET)public Result recommend() {return Result.ok(recruitService.findTop4ByStateOrderByCreatetimeDesc("2"));}
1.5.4 测试
访问如下网址进行测试:http://localhost:9002/enterprise/search/recommend
1.6 最新职位列表
需求:查询状态不为0并以创建日期降序排序,查询前12条记录
1.6.1 RecruitDao新增方法定义
/*** 最新职位列表** @param state* @return*/List<Recruit> findByStateNotOrderByCreatetimeDesc(String state);// where state != ? order by createtime desc
1.6.2 RecruitService新增方法
public List<Recruit> newList(String state) {return recruitDao.findByStateNotOrderByCreatetimeDesc(state);}
1.6.3 RecruitController新增方法
/*** 查询最新职位列表** @return*/@RequestMapping(value = "/search/newlist", method = RequestMethod.GET)public Result newList() {return Result.ok(recruitService.newList("0"));}
1.6.4 测试
访问如下网址进行测试:http://localhost:9002/enterprise/search/newslist
二、问答微服务模块
2.1 原型
先来看一下页面原型,如图:
招聘微服务主要有三个大功能:最新回答、热门回答和等待回答
2.2 表结构分析
2.2.1 问题表
2.2.2 回复表
2.2.3 问答标签中间表
2.3 代码生成
接下来使用开源代码生成器codeutil
来完成代码的生成
开源网址: https://gitee.com/chuanzhiliubei/codeutil
生成步骤:
- 使用代码生成器生成招聘微服务代码
tensquare_qa
- 拷贝到当前工程,并在父工程引入
- 修改
Application
类名称为QAApplication
- 修改
application.yml
中的端口为9003
,url
为jdbc:mysql://127.0.0.1:3306/tensquare_qa?characterEncoding=UTF8
- 使用
Postman
进行测试
2.4 最新回答列表
需求:最新回复的问题显示在上方, 按回复时间降序排序
2.4.1 创建中间表pl的实体类
新建PL.java
如下:
@Entity
@Table(name = "tb_pl")
public class PL implements Serializable {@Idprivate String problemid;@Idprivate String lableid;public String getProblemid() {return problemid;}public void setProblemid(String problemid) {this.problemid = problemid;}public String getLableid() {return lableid;}public void setLableid(String lableid) {this.lableid = lableid;}
}
2.4.2 ProblemDao新增方法定义
/*** 根据标签ID查询最新问题列表* @param labelId* @param pageable* @return*/@Query(value = "select p from Problem p where id in(select problemid from PL where labelid = ?1) order by replytime desc")public Page<Problem> findNewListByLabelId(String labelId, Pageable pageable);
2.4.3 ProblemService新增方法
/*** 查询最新回答列表** @param labelId* @param page* @param size* @return*/public Page<Problem> findNewListByLabelId(String labelId, int page, int size) {PageRequest pageRequest = PageRequest.of(page - 1, size);return problemDao.findNewListByLabelId(labelId, pageRequest);}
2.4.4 ProblemController新增方法
/*** 最新回答* @param labelId* @param page* @param size* @return*/@RequestMapping(value = "/newlist/{labelId}/{page}/{size}")public Result findNewListByLabelId(@PathVariable String labelId, @PathVariable int page, @PathVariable int size) {Page<Problem> pageList = problemService.findNewListByLabelId(labelId, page, size);PageResult pageResult = new PageResult<>(pageList.getTotalPages(), pageList.getContent());return Result.ok(pageResult);}
2.4.5 测试
访问如下网址进行测试:http://localhost:9003/problem/newlist/1/1/5
2.5 推荐职位列表
需求:按回复数降序排序
2.5.1 ProblemDao新增方法定义
/*** 根据标签ID查询热门问题列表** @param labelId* @param pageable* @return*/@Query(value = "select p from Problem p where id in(select problemid from PL where labelid = ?1) order by reply desc")public Page<Problem> findHotListByLabelId(String labelId, Pageable pageable);
2.5.2 ProblemService新增方法
/*** 查询热门回答列表** @param labelId* @param page* @param size* @return*/public Page<Problem> findHotListByLabelId(String labelId, int page, int size) {PageRequest pageRequest = PageRequest.of(page - 1, size);return problemDao.findHotListByLabelId(labelId, pageRequest);}
2.5.3 ProblemController新增方法
/*** 热门回答** @param labelId* @param page* @param size* @return*/@RequestMapping(value = "/hotlist/{labelId}/{page}/{size}")public Result findHotListByLabelId(@PathVariable String labelId, @PathVariable int page, @PathVariable int size) {Page<Problem> pageList = problemService.findNewListByLabelId(labelId, page, size);PageResult pageResult = new PageResult<>(pageList.getTotalPages(), pageList.getContent());return Result.ok(pageResult);}
2.5.4 测试
访问如下网址进行测试:http://localhost:9003/problem/hotlist/1/1/5
2.6 等待回答列表
需求:查询尚无人回答列表(reply=0)
2.6.1 ProblemDao新增方法定义
/*** 根据标签ID查询等待回答问题列表** @param labelId* @param pageable* @return*/@Query(value = "select p from Problem p where id in(select problemid from PL where labelid = ?1) and reply =0 order by createtime desc")public Page<Problem> findWaitReplyListByLabelId(String labelId, Pageable pageable);
2.6.2 ProblemService新增方法
/*** 查询等待回答列表** @param labelId* @param page* @param size* @return*/public Page<Problem> findWaitReplyListByLabelId(String labelId, int page, int size) {PageRequest pageRequest = PageRequest.of(page - 1, size);return problemDao.findWaitReplyListByLabelId(labelId, pageRequest);}
2.6.3 ProblemController新增方法
/*** 等待回答** @param labelId* @param page* @param size* @return*/@RequestMapping(value = "/waitlist/{labelId}/{page}/{size}")public Result findWaitReplyListByLabelId(@PathVariable String labelId, @PathVariable int page, @PathVariable int size) {Page<Problem> pageList = problemService.findWaitReplyListByLabelId(labelId, page, size);PageResult pageResult = new PageResult<>(pageList.getTotalPages(), pageList.getContent());return Result.ok(pageResult);}
2.6.4 测试
访问如下网址进行测试:http://localhost:9003/problem/waitlist/1/1/5
三、小结
本文主要介绍了:
- 招聘表结构分析&微服务模块开发
- 问答表结构分析&微服务模块开发
- 通过工具自动生成代码
- HQL语句编写
这篇关于十次方微服务项目实战05--招聘问答模块微服务开发及代码自动生成的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!