## 在页面一开始 - 向后端发送给网络请求 - 后端接口对应代码为: ```java @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 getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) { return R.ok(invoiceSettingService.queryById(id)); } } ``` - 其中`id`默认为`1` - `R`: ```java @Data @NoArgsConstructor public class R 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 R ok() { return restResult(null, SUCCESS, "操作成功"); } public static R ok(T data) { return restResult(data, SUCCESS, "操作成功"); } public static R ok(String msg) { return restResult(null, SUCCESS, msg); } public static R ok(String msg, T data) { return restResult(data, SUCCESS, msg); } public static R fail() { return restResult(null, FAIL, "操作失败"); } public static R fail(String msg) { return restResult(null, FAIL, msg); } public static R fail(T data) { return restResult(data, FAIL, "操作失败"); } public static R fail(String msg, T data) { return restResult(data, FAIL, msg); } public static R fail(int code, String msg) { return restResult(null, code, msg); } /** * 返回警告消息 * * @param msg 返回内容 * @return 警告消息 */ public static R warn(String msg) { return restResult(null, HttpStatus.WARN, msg); } /** * 返回警告消息 * * @param msg 返回内容 * @param data 数据对象 * @return 警告消息 */ public static R warn(String msg, T data) { return restResult(data, HttpStatus.WARN, msg); } private static R restResult(T data, int code, String msg) { R r = new R<>(); r.setCode(code); r.setData(data); r.setMsg(msg); return r; } public static Boolean isError(R ret) { return !isSuccess(ret); } public static Boolean isSuccess(R ret) { return R.SUCCESS == ret.getCode(); } } ``` - `InvoiceSettingVo`: ```java @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`,那么就将数据填入对应的输入框当中 - 否则返回提示异常信息 ## 点击保存 - 弹出弹出框,弹出框中显示:"请确认是否填写完成" - 用户点击确认,向后端发送网络请求 - 后端接口对应代码为: ```java @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 edit(@Validated(EditGroup.class) @RequestBody InvoiceSettingBo bo) { return toAjax(invoiceSettingService.updateByBo(bo)); } } ``` - `InvoiceSettingBo`: ```java @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`: ```java @Data @NoArgsConstructor public class R 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 R ok() { return restResult(null, SUCCESS, "操作成功"); } public static R ok(T data) { return restResult(data, SUCCESS, "操作成功"); } public static R ok(String msg) { return restResult(null, SUCCESS, msg); } public static R ok(String msg, T data) { return restResult(data, SUCCESS, msg); } public static R fail() { return restResult(null, FAIL, "操作失败"); } public static R fail(String msg) { return restResult(null, FAIL, msg); } public static R fail(T data) { return restResult(data, FAIL, "操作失败"); } public static R fail(String msg, T data) { return restResult(data, FAIL, msg); } public static R fail(int code, String msg) { return restResult(null, code, msg); } /** * 返回警告消息 * * @param msg 返回内容 * @return 警告消息 */ public static R warn(String msg) { return restResult(null, HttpStatus.WARN, msg); } /** * 返回警告消息 * * @param msg 返回内容 * @param data 数据对象 * @return 警告消息 */ public static R warn(String msg, T data) { return restResult(data, HttpStatus.WARN, msg); } private static R restResult(T data, int code, String msg) { R r = new R<>(); r.setCode(code); r.setData(data); r.setMsg(msg); return r; } public static Boolean isError(R ret) { return !isSuccess(ret); } public static Boolean isSuccess(R ret) { return R.SUCCESS == ret.getCode(); } } ``` - 根据后端返回的状态 - 如果为`200`,则提示保存成功 - 否则提示异常信息