向后端发送给网络请求
后端接口对应代码为:
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/web/setting")
public class InvoiceSettingController extends BaseController {
private final IInvoiceSettingService invoiceSettingService;
/**
* 获取发票设置详细信息
*
* @param id 主键
*/
@SaCheckPermission("web:setting:query")
@GetMapping("/{id}")
public R<InvoiceSettingVo> getInfo(@NotNull(message = "主键不能为空")
@PathVariable Long id) {
return R.ok(invoiceSettingService.queryById(id));
}
}
其中id
默认为1
R
:
@Data
@NoArgsConstructor
public class R<T> implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 成功
*/
public static final int SUCCESS = 200;
/**
* 失败
*/
public static final int FAIL = 500;
private int code;
private String msg;
private T data;
public static <T> R<T> ok() {
return restResult(null, SUCCESS, "操作成功");
}
public static <T> R<T> ok(T data) {
return restResult(data, SUCCESS, "操作成功");
}
public static <T> R<T> ok(String msg) {
return restResult(null, SUCCESS, msg);
}
public static <T> R<T> ok(String msg, T data) {
return restResult(data, SUCCESS, msg);
}
public static <T> R<T> fail() {
return restResult(null, FAIL, "操作失败");
}
public static <T> R<T> fail(String msg) {
return restResult(null, FAIL, msg);
}
public static <T> R<T> fail(T data) {
return restResult(data, FAIL, "操作失败");
}
public static <T> R<T> fail(String msg, T data) {
return restResult(data, FAIL, msg);
}
public static <T> R<T> fail(int code, String msg) {
return restResult(null, code, msg);
}
/**
* 返回警告消息
*
* @param msg 返回内容
* @return 警告消息
*/
public static <T> R<T> warn(String msg) {
return restResult(null, HttpStatus.WARN, msg);
}
/**
* 返回警告消息
*
* @param msg 返回内容
* @param data 数据对象
* @return 警告消息
*/
public static <T> R<T> warn(String msg, T data) {
return restResult(data, HttpStatus.WARN, msg);
}
private static <T> R<T> restResult(T data, int code, String msg) {
R<T> r = new R<>();
r.setCode(code);
r.setData(data);
r.setMsg(msg);
return r;
}
public static <T> Boolean isError(R<T> ret) {
return !isSuccess(ret);
}
public static <T> Boolean isSuccess(R<T> ret) {
return R.SUCCESS == ret.getCode();
}
}
InvoiceSettingVo
:
@Data
@ExcelIgnoreUnannotated
@AutoMapper(target = InvoiceSetting.class)
public class InvoiceSettingVo implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* id
*/
@ExcelProperty(value = "id")
private Long id;
/**
* 收款人
*/
@ExcelProperty(value = "收款人")
private String payee;
/**
* 复核人
*/
@ExcelProperty(value = "复核人")
private String reviewer;
/**
* 开票人
*/
@ExcelProperty(value = "开票人")
private String drawer;
/**
* 开票人类型
* 0、固定人员名称
* 1、跟随账号名称
*/
@ExcelProperty(value = "开票人类型")
private Integer drawerType;
}
根据后端返回来的状态
200
,那么就将数据填入对应的输入框当中弹出弹出框,弹出框中显示:"请确认是否填写完成"
用户点击确认,向后端发送网络请求
后端接口对应代码为:
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/web/setting")
public class InvoiceSettingController extends BaseController {
private final IInvoiceSettingService invoiceSettingService;
/**
* 修改发票设置
*/
@SaCheckPermission("web:setting:edit")
@Log(title = "发票设置", businessType = BusinessType.UPDATE)
@RepeatSubmit()
@PutMapping()
public R<Void> edit(@Validated(EditGroup.class) @RequestBody InvoiceSettingBo bo) {
return toAjax(invoiceSettingService.updateByBo(bo));
}
}
InvoiceSettingBo
:
@Data
@EqualsAndHashCode(callSuper = true)
@AutoMapper(target = InvoiceSetting.class, reverseConvertGenerate = false)
public class InvoiceSettingBo extends BaseEntity {
/**
* id
*/
@NotNull(message = "id不能为空", groups = { EditGroup.class })
private Long id;
/**
* 收款人
*/
private String payee;
/**
* 复核人
*/
private String reviewer;
/**
* 开票人
*/
private String drawer;
/**
* 开票人类型
* 0、固定人员名称
* 1、跟随账号名称
*/
private Integer drawerType;
}
R
:
@Data
@NoArgsConstructor
public class R<T> implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 成功
*/
public static final int SUCCESS = 200;
/**
* 失败
*/
public static final int FAIL = 500;
private int code;
private String msg;
private T data;
public static <T> R<T> ok() {
return restResult(null, SUCCESS, "操作成功");
}
public static <T> R<T> ok(T data) {
return restResult(data, SUCCESS, "操作成功");
}
public static <T> R<T> ok(String msg) {
return restResult(null, SUCCESS, msg);
}
public static <T> R<T> ok(String msg, T data) {
return restResult(data, SUCCESS, msg);
}
public static <T> R<T> fail() {
return restResult(null, FAIL, "操作失败");
}
public static <T> R<T> fail(String msg) {
return restResult(null, FAIL, msg);
}
public static <T> R<T> fail(T data) {
return restResult(data, FAIL, "操作失败");
}
public static <T> R<T> fail(String msg, T data) {
return restResult(data, FAIL, msg);
}
public static <T> R<T> fail(int code, String msg) {
return restResult(null, code, msg);
}
/**
* 返回警告消息
*
* @param msg 返回内容
* @return 警告消息
*/
public static <T> R<T> warn(String msg) {
return restResult(null, HttpStatus.WARN, msg);
}
/**
* 返回警告消息
*
* @param msg 返回内容
* @param data 数据对象
* @return 警告消息
*/
public static <T> R<T> warn(String msg, T data) {
return restResult(data, HttpStatus.WARN, msg);
}
private static <T> R<T> restResult(T data, int code, String msg) {
R<T> r = new R<>();
r.setCode(code);
r.setData(data);
r.setMsg(msg);
return r;
}
public static <T> Boolean isError(R<T> ret) {
return !isSuccess(ret);
}
public static <T> Boolean isSuccess(R<T> ret) {
return R.SUCCESS == ret.getCode();
}
}
根据后端返回的状态
200
,则提示保存成功