当前位置:网站首页>30: Chapter 3: develop Passport Service: 13: develop [change / improve user information, interface]; (use * * * Bo class to accept parameters, and use parameter verification)
30: Chapter 3: develop Passport Service: 13: develop [change / improve user information, interface]; (use * * * Bo class to accept parameters, and use parameter verification)
2022-07-04 13:55:00 【Small withered forest】
explain :
(1) The content of this blog : Development 【 change / Improve user information , Interface 】;
Catalog
(2) stay UserServiceImpl in , Implement this method ;
zero : Rationality of this blog ;( Or rather, :【 change / Improve user information , Interface 】 What is it? )
One : Formal development ;
1. stay 【model】 In model engineering , establish UpdateUserInfoBO class , To undertake 【 change / Improve user information , Interface 】 Parameters of ;
UpdateUserInfoBO class :
package com.imooc.bo; import com.fasterxml.jackson.annotation.JsonFormat; import org.hibernate.validator.constraints.Length; import javax.validation.constraints.*; import java.util.Date; public class UpdateUserInfoBO { @NotBlank(message = " user ID Can't be empty ") private String id; @NotBlank(message = " User nickname cannot be empty ") @Length(max = 12, message = " The user's nickname cannot exceed 12 position ") private String nickname; @NotBlank(message = " User avatar cannot be empty ") private String face; @NotBlank(message = " The real name cannot be empty ") private String realname; @Email @NotBlank(message = " The message cannot be empty ") private String email; // Determines if the string is empty , Best use @NotBlank; And judgment integer, Need to use @NotNull @NotNull(message = " Please choose a gender ") @Min(value = 0, message = " Wrong sex choice ") @Max(value = 1, message = " Wrong sex choice ") private Integer sex; @NotNull(message = " Please select a birthday date ") @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd") // After the front-end date string is transferred to the back-end , Convert to Date type private Date birthday; @NotBlank(message = " Please select your city ") private String province; @NotBlank(message = " Please select your city ") private String city; @NotBlank(message = " Please select your city ") private String district; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getNickname() { return nickname; } public void setNickname(String nickname) { this.nickname = nickname; } public String getFace() { return face; } public void setFace(String face) { this.face = face; } public String getRealname() { return realname; } public void setRealname(String realname) { this.realname = realname; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public Integer getSex() { return sex; } public void setSex(Integer sex) { this.sex = sex; } public Date getBirthday() { return birthday; } public void setBirthday(Date birthday) { this.birthday = birthday; } public String getProvince() { return province; } public void setProvince(String province) { this.province = province; } public String getCity() { return city; } public void setCity(String city) { this.city = city; } public String getDistrict() { return district; } public void setDistrict(String district) { this.district = district; } }explain :
(1) This BO Class is used to undertake 【 change / Improve user information , Interface 】 Parameters of , That is the content of the following form ;;; therefore , The attributes in this interface are not written in vain ;
(2) We use this BO When class accepts parameters , Also added a lot of checks ;
● utilize @JsonFormat Annotation to solve the problem of time , stay 【RESTful Development style 6:RESTful Basic use IV :JSON serialize ;(jackson Components , And some of them @JsonFormat Annotation to solve the problem of time ;)】 I introduced it for the first time ;
(3) Actually , The content of this form , The front end is also verified ;( This is easy to understand , I used to write it myself C# When the form program , It has also been verified on the front-end form , similar )
2. stay 【api】 Interface Engineering UserControllerApi Interface , Definition 【 change / Improve user information , Interface 】;
/** * 【 modify / Improve user information , Interface 】 * @param updateUserInfoBO * @return */ @ApiOperation(value = " modify / Improve user information ", notes = " modify / Improve user information ", httpMethod = "POST") @PostMapping("/updateUserInfo") // Set the routing , This needs to be agreed between the front and back ; public GraceJSONResult updateUserInfo(@RequestBody @Valid UpdateUserInfoBO updateUserInfoBO, BindingResult result);explain :
(1) Content description ;
● Once the verification fails , There is an error message , We can go through 【BindingResult result】 To get the corresponding error information ; therefore , Here in the parameter , It has also been introduced. 【BindingResult result】;
3. stay 【user】 User microservices UserController Class , To achieve 【 change / Improve user information , Interface 】;
/** * 【 modify / Improve user information , Interface 】 * * @param updateUserInfoBO * @param result * @return */ @Override public GraceJSONResult updateUserInfo(@Valid UpdateUserInfoBO updateUserInfoBO, BindingResult result) { //0. Judge BindingResult Whether the error message of validation failure is saved in , If there is , It indicates that there is a problem with the input of the front end ; // that , We get this error message , And build a GraceJSONResult Unified return object , return ; if (result.hasErrors()) { Map<String, String> map = getErrorsFromBindingResult(result);// therefore , This class needs to inherit BaseController return GraceJSONResult.errorMap(map); } //1. Perform an update operation userService.updateUserInfo(updateUserInfoBO); return GraceJSONResult.ok(); }explain :
(1) Content description ;
4. stay 【user】 User microservices UserService Interface , Define a 【 modify / Improve user information , And activate the user 】 Methods ;;; stay UserServiceImpl in , Implement this method ;
(1) stay 【user】 User microservices UserService Interface , Define a 【 modify / Improve user information , And activate the user 】 Methods
……………………………………………………
(2) stay UserServiceImpl in , Implement this method ;
/** * modify / Improve user information , And activate the user ; * * @param updateUserInfoBO */ @Override public void updateUserInfo(UpdateUserInfoBO updateUserInfoBO) { // Pass it from the front updateUserInfoBO Attribute value in ,copy To a AppUser Go to the object ; AppUser userInfo = new AppUser(); BeanUtils.copyProperties(updateUserInfoBO, userInfo); // Reset its update time userInfo.setUpdatedTime(new Date()); // Set its user status , Set its state to 1( Is activated ); userInfo.setActiveStatus(UserStatus.ACTIVE.type); // and mybatis-plus The routine is basically the same , We use updateByPrimaryKeySelective() Method ( This method only updates those in the database table userInfo In some ,, Nothing will move ); // Instead of using updateByPrimaryKey();( This method will completely update the contents of the database table ,,userInfo There is no the , It will be set to empty ), int result = appUserMapper.updateByPrimaryKeySelective(userInfo); if (result != 1) {// If the return value of the above method is not 1, It means that there is something wrong with the update operation , Then we throw an exception ; GraceException.display(ResponseStatusEnum.USER_UPDATE_ERROR); } }explain :
(1) Content description ;
3、 ... and : test ;
Statement :
We can do it in Swagger2 Test on the page , You can also use Postman To test ;
test :
(1) First, the whole situation install Look at the whole project ;
(2) then , start-up 【user】 Main startup class of microservice ;
(3) then , Visit the page to update / Improve user information ;
边栏推荐
- 面试拆解:系统上线后Cpu使用率飙升如何排查?
- Distributed base theory
- 2022年起重机械指挥考试模拟100题模拟考试平台操作
- Excuse me, have you encountered this situation? CDC 1.4 cannot use timestamp when connecting to MySQL 5.7
- Annual comprehensive analysis of China's mobile reading market in 2022
- XML入门一
- Redis —— How To Install Redis And Configuration(如何快速在 Ubuntu18.04 与 CentOS7.6 Linux 系统上安装 Redis)
- . Net delay queue
- 忠诚协议是否具有法律效力
- Flet tutorial 03 basic introduction to filledbutton (tutorial includes source code) (tutorial includes source code)
猜你喜欢

结合案例:Flink框架中的最底层API(ProcessFunction)用法

SCM polling program framework based on linked list management

"Pre training weekly" issue 52: shielding visual pre training and goal-oriented dialogue

Xue Jing, director of insight technology solutions: Federal learning helps secure the flow of data elements

Oracle was named the champion of Digital Innovation Award by Ventana research

Oracle 被 Ventana Research 评为数字创新奖总冠军

One of the solutions for unity not recognizing riders

Comparative study of the gods in the twilight Era

Go 语言入门很简单:Go 实现凯撒密码

嵌入式编程中五个必探的“潜在错误”
随机推荐
ViewBinding和DataBinding的理解和区别
Dgraph: large scale dynamic graph dataset
CTF competition problem solution STM32 reverse introduction
光环效应——谁说头上有光的就算英雄
FS4056 800mA充电ic 国产快充电源ic
C语言集合运算
One of the solutions for unity not recognizing riders
逆向调试入门-PE结构-资源表07/07
Xue Jing, director of insight technology solutions: Federal learning helps secure the flow of data elements
高质量软件架构的唯一核心指标
Three schemes to improve the efficiency of MySQL deep paging query
易周金融 | Q1保险行业活跃人数8688.67万人 19家支付机构牌照被注销
. Net using redis
Haproxy high availability solution
CVPR 2022 | 大幅减少零样本学习所需的人工标注,提出富含视觉信息的类别语义嵌入(源代码下载)...
It is six orders of magnitude faster than the quantum chemical method. An adiabatic artificial neural network method based on adiabatic state can accelerate the simulation of dual nitrogen benzene der
30:第三章:开发通行证服务:13:开发【更改/完善用户信息,接口】;(使用***BO类承接参数,并使用了参数校验)
CVPR 2022 | transfusion: Lidar camera fusion for 3D target detection with transformer
Web knowledge supplement
E-week finance | Q1 the number of active people in the insurance industry was 86.8867 million, and the licenses of 19 Payment institutions were cancelled














