在实际工程中的代码应该尽量保证良好的代码风格,这里以前面的例子为例:向数据库中插入学生信息时,如果学号满足要求,插入成功,则返回该记录具体信息字段;如果插入失败,则返回错误及错误提示信息。

第一步:首先建立一个消息返回内容类Result.java

Spring boot之代码规范书写


第二步:读题目意思,得知对消息的返回应该有一个统一的格式,因此创建ResultUtil.java类,封装消息返回的格式

Spring boot之代码规范书写


第三步:在添加学生的StudentController.java中实现插入结果的成功/失败的提示

Spring boot之代码规范书写


学号的约束条件:

Spring boot之代码规范书写


执行结果:

Spring boot之代码规范书写Spring boot之代码规范书写


参考资料:http://www.imooc.com/video/14341


相关文章:

  • 2022-12-23
  • 2021-12-12
  • 2021-09-29
  • 2021-05-06
  • 2021-08-22
  • 2021-09-05
  • 2022-12-23
猜你喜欢
  • 2022-01-17
  • 2022-01-08
  • 2021-12-12
  • 2021-12-28
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案