如果这个项目让你有所收获,记得 Star 关注哦,这对我是非常不错的鼓励与支持。
源码地址(后端):https://gitee.com/csps/mingyue
源码地址(前端):https://gitee.com/csps/mingyue-ui
文档地址:https://gitee.com/csps/mingyue/wikis
模块化 mybatis,便于管理 mybatis,并使其与项目解耦。
<dependencies>
<dependency>
<groupId>com.csp.mingyuegroupId>
<artifactId>mingyue-common-coreartifactId>
dependency>
<dependency>
<groupId>com.mysqlgroupId>
<artifactId>mysql-connector-jartifactId>
dependency>
<dependency>
<groupId>com.baomidougroupId>
<artifactId>mybatis-plus-boot-starterartifactId>
dependency>
<dependency>
<groupId>com.baomidougroupId>
<artifactId>mybatis-plus-generatorartifactId>
dependency>
<dependency>
<groupId>org.apache.velocitygroupId>
<artifactId>velocity-engine-coreartifactId>
dependency>
dependencies>
MybatisPlusConfiguration 文件迁移入 mingyue-common-mybatis
模块
<dependency>
<groupId>com.csp.mingyuegroupId>
<artifactId>mingyue-common-mybatisartifactId>
<version>${project.version}version>
dependency>
<dependency>
<groupId>com.csp.mingyuegroupId>
<artifactId>mingyue-common-coreartifactId>
dependency>
<dependency>
<groupId>com.csp.mingyuegroupId>
<artifactId>mingyue-common-mybatisartifactId>
dependency>
public interface SysUserService extends IService<SysUser> {
SysUser getSysUserInfoByUsername(String username);
}
@GetMapping("getSysUserInfoByUsername")
public R<SysUser> getSysUserInfoByUsername(String username) {
return R.ok(sysUserService.getSysUserInfoByUsername(username));
}
发送请求:
curl --location --request GET 'http://127.0.0.1:8000/sysUser/getSysUserInfoByUsername?username=mingyue' \
--header 'User-Agent: Apifox/1.0.0 (https://www.apifox.cn)' \
--header 'Accept: */*' \
--header 'Host: 127.0.0.1:8000' \
--header 'Connection: keep-alive'
返回结果:
{
"code": 200,
"msg": "操作成功",
"data": {
"userId": 1,
"username": "mingyue",
"nickname": "明月",
"sex": "0",
"password": "123456",
"phone": "13260718262",
"email": null,
"avatar": null,
"lockFlag": "0",
"delFlag": "0",
"createTime": null,
"updateTime": null,
"createBy": null,
"updateBy": null
}
}
后续添加的接口或者服务都走网关调用了,不再直接访问服务!
# 系统服务
- id: mingyue-system
uri: lb://mingyue-system-biz
predicates:
- Path=/sys/**
filters:
- StripPrefix=1
发送请求:
curl --location --request GET 'http://127.0.0.1:9100/sys/sysUser/getSysUserInfoByUsername?username=mingyue' \
--header 'User-Agent: Apifox/1.0.0 (https://www.apifox.cn)' \
--header 'Accept: */*' \
--header 'Host: 127.0.0.1:9100' \
--header 'Connection: keep-alive'
返回结果:
{
"code": 200,
"msg": "操作成功",
"data": {
"userId": 1,
"username": "mingyue",
"nickname": "明月",
"sex": "0",
"password": "123456",
"phone": "13260718262",
"email": null,
"avatar": null,
"lockFlag": "0",
"delFlag": "0",
"createTime": null,
"updateTime": null,
"createBy": null,
"updateBy": null
}
}
整理一下,模块和代码结构舒服多了~~~,用户名查询的接口已经开发完成啦。
是时候引入接口文档并聚合各模块,方便提供给前端童鞋联调喽~~~