luckyzb! 2021-11-18 22:27 采纳率: 47.1%
浏览 219
已结题

关于后端代码实现逻辑运算

模块中需要在前端实现输入两个字段值,第三个字段值会通过后段的计算代码自动计算出来传到前端。这个要在后端怎么代码呢?例如普通的两个数的求和功能dao service controller 有例子吗 springboot vue

  • 写回答

7条回答 默认 最新

  • lzh_me 2021-11-19 10:27
    关注

    演示代码:

    
    <template>
        <div class="hello">
            <h1>{{ msg }}</h1>
            <ul>
                <label for="parameter1">参数1:</label>
                <input type="number" placeholder="请输入参数1" v-model="parameter1">
                <br />
                <label for="parameter2">参数2:</label>
                <input type="number" placeholder="请输入参数2" v-model="parameter2">
                <br />
                <button type="button" @click="test">测试</button>
                <br />
                <label for="sum">结果:</label>
                <li>{{ sum }}</li>
            </ul>
        </div>
    </template>
    
    <script>
        export default {
            name: 'HelloWorld',
            props: {
                msg: String
            },
            data() {
                return {
                    parameter1: '',
                    parameter2: '',
                    sum: ''
                }
            },
            methods: {
                test() {
                    this.$http.get('http://localhost:8090/test/getSum', {
                        params: {
                            parameter1: this.parameter1,
                            parameter2: this.parameter2
                        }
                    }).then(function(res) {
                        this.sum = res.data;
                    }, function(res) {
                        console.log('失败')
                    })
                }
            },
        }
    </script>
    
    <!-- Add "scoped" attribute to limit CSS to this component only -->
    <style scoped>
        h3 {
            margin: 40px 0 0;
        }
    
        ul {
            list-style-type: none;
            padding: 0;
        }
    
        li {
            display: inline-block;
            margin: 0 10px;
        }
    
        a {
            color: #42b983;
        }
    </style>
    
    
    
    @RestController
    @RequestMapping("/test")
    public class TesController {
    
        @GetMapping(value = "/getSum")
        @CrossOrigin("http://localhost:8080")
        public int getSum(@RequestParam( name = "parameter1") int parameter1,
                             @RequestParam( name = "parameter2")int parameter2) {
            return parameter1 + parameter2;
        }
    }
    
    
    评论

报告相同问题?

问题事件

  • 系统已结题 11月26日
  • 赞助了问题酬金 11月18日
  • 创建了问题 11月18日

悬赏问题

  • ¥50 Python调用Canalyzer发报文
  • ¥15 关于使用Azure Auto ML时上传的数据无法加载MLTable问题
  • ¥15 flume采集日志信息到hdfs
  • ¥15 电脑重启发现主机转屏幕不亮
  • ¥20 yolo5 打包exe 运行报错
  • ¥15 python如何过滤应用层协议
  • ¥15 newtonsoft解析慢。
  • ¥15 请问前端如何在企业微信内通过聊天点击链接唤起第三方app
  • ¥15 纯C++ 简单图色对比 灵敏度低的问题
  • ¥15 麒麟ARM机器安装chromium浏览器