新建项目
1 新建一个
image-20210123132141826
Helloworld
关系:web依赖service调用api
image-20210206211503462
过程:web->service->api->service-web
api模块
image-20210123123015351
service模块
image-20210123122928544
web模块
image-20210123122810861
效果:
image-20210123122555453
自定义Result类
image-20210123132715941
创建一个枚举类
image-20210123132457733
测试:
修改TextContCroller类:根据需要测试的接口,修改这个类,或者修改TestService类
image-20210123133240534
全局异常:
image-20210123133401633
自定义异常:
image-20210123133458916
Success:
image-20210123133543774
error:
image-20210123133702549
引入mybatis-plus
利用sql语句查询数据库
在全部模块添加mybatis-plus依赖
在service里添加jdbc和mysql的依赖
在service添加
testMapper.xml:
image-20210123151744745
application.yml:
image-20210123152339085
在api模块添加
image-20210123151216319
测试:
修改TestContCroller类
image-20210123151445480
效果:
image-20210123151536105
引入swagger2
在web模块添加swagger-ui依赖:
image-20210123173438190
配置前效果:
image-20210207001740983
Swagger2Config:
image-20210123173844171
代码生成器
mybatis-plus-generator
在web模块添加依赖
image-20210207022240824
根据官方文档提供的示例代码进行修改
生成代码
后台登录模块
在web模块引入spring-boot-starter-security依赖
image-20210207121510700
测试:
启动后,我们会获取到一个密码(随机)
image-20210207121556410
访问后,进行登录:
image-20210207121655550
image-20210207121844640