• 前后端------新增/修改


    index.vue 跳转到form.vue   

    新增-编辑按钮

    前端

    1. index.vue:
    2. <el-button type="primary" @click="addOrUpdateHandle()">新增el-button>
    3. /**
    4. * index.vue 跳到 Form.vue
    5. */
    6. addOrUpdateHandle(id, isDetail) {
    7. this.formVisible = true
    8. this.$nextTick(() => {
    9. this.$refs.JNPFForm.init(id, isDetail)
    10. })
    11. },
    12. Form.vue:
    13. /**
    14. * 初始化表单数据
    15. * @param id 主键值
    16. * @param isDetail 是否是详情页面,控制是否可编辑
    17. */
    18. init(id, isDetail) {
    19. this.dataForm.id = id || 0;
    20. this.visible = true;
    21. this.isDetail = isDetail || false;
    22. this.$nextTick(() => {
    23. this.$refs['elForm'].resetFields();
    24. if (this.dataForm.id) {
    25. this.loading = true
    26. //加载表单数据
    27. getOLoad(this.dataForm.id).then(res => {
    28. this.dataForm = res.data
    29. this.loading = false
    30. })
    31. } else {
    32. this.clearData(this.dataForm)
    33. }
    34. });
    35. this.$store.commit('generator/UPDATE_RELATION_DATA', {})
    36. },
    37. /**
    38. * 清除Form中的数据
    39. */
    40. clearData(data) {
    41. for (let key in data) {
    42. if (data[key] instanceof Array) {
    43. data[key] = [];
    44. } else if (data[key] instanceof Object) {
    45. this.clearData(data[key]);
    46. } else {
    47. data[key] = "";
    48. }
    49. }
    50. },

    前端跳后端接口

    1. /**
    2. * 获取表单详细(编辑页面调用)
    3. * @param id 主键值
    4. */
    5. export function getOLoad(id) {
    6. return request({
    7. url: define.api+'/getOLoad/' + id,
    8. method: 'GET'
    9. })
    10. }

    后端接口

    1. @RequestMapping("/user")
    2. public class OLoadAnalysisController {
    3. /**
    4. * 根据id获取表单信息(编辑表单)
    5. * @param id 主键
    6. */
    7. @GetMapping("/{id}")
    8. public ActionResult info(@PathVariable("id") String id){
    9. }
    10. }

    确定按钮

    前端

    1. "primary" @click="dataFormSubmit()" v-if="!isDetail"> 确 定
    2. /**
    3. * 表单确定按钮
    4. */
    5. dataFormSubmit() {
    6. this.$refs['elForm'].validate((valid) => {
    7. if (valid) {
    8. this.request()
    9. }
    10. })
    11. },
    12. /**
    13. * 数据格式化,将提交的表单数据转为JSON对象
    14. */
    15. dataList() {
    16. var _data = JSON.parse(JSON.stringify(this.dataForm));
    17. return _data;
    18. },
    19. /**
    20. * 表单提交调用api接口方法
    21. */
    22. request() {
    23. var _data = this.dataList()
    24. if (!this.dataForm.id) {
    25. addOLoadAnalysis(_data).then((res) => {
    26. })
    27. } else {
    28. updateOLoadAnalysis(this.dataForm.id, _data).then((res) => {
    29. })
    30. }
    31. },

    前端跳后端接口

    1. /**
    2. * 新增表单保存数据
    3. * @param data 提交的表单对象
    4. */
    5. export function addOLoadAnalysis(data) {
    6. return request({
    7. url: define.api+'/user',
    8. method: 'POST',
    9. data
    10. })
    11. }
    12. /**
    13. * 修改表单保存数据
    14. * @param data 提交的表单对象
    15. */
    16. export function updateOLoadAnalysis(id, data) {
    17. return request({
    18. url: define.api+'/user/' + id,
    19. method: 'PUT',
    20. data
    21. })
    22. }

    后端

    1. @RequestMapping("/user")
    2. public class OLoadAnalysisController {
    3. /**
    4. * 新增数据保存
    5. *
    6. * @param userVo表单提交对象
    7. * @return
    8. */
    9. @PostMapping
    10. @DSTransactional
    11. public ActionResult create(@RequestBody @Valid UserVo userVo){
    12. }
    13. /**
    14. * 更新数据保存接口
    15. * @param id 主键
    16. * @param userVo表单信息
    17. */
    18. @PutMapping("/{id}")
    19. @DSTransactional
    20. public ActionResult update(@PathVariable("id") String id,@RequestBody @Valid UserVo userVo){
    21. }
    22. }

  • 相关阅读:
    MyBatis 源码系列:MyBatis 解析配置文件、二级缓存、SQL
    UniApp 中 nvue 盒模型入门
    HDP集群Kafka开启SASLPLAINTEXT安全认证
    合宙Air724UG LuatOS-Air LVGL API控件-窗口 (Window)
    【教学类-36-10】20230908方脸爷爷和圆脸奶奶(midjounery-niji)(中班:《我爱我家》数:连线、涂色)
    C#:实现DisjointSet不相交集算法(附完整源码)
    Windows---命令打开截图工具,.bat文件执行
    【每日一题】路径总和 III
    前端学习-平面转换
    Python virtualenv工具设置虚拟环境和VS code调试Python
  • 原文地址:https://blog.csdn.net/xy58451921/article/details/130599325