软件园学生在线

  • {{ item.name }}
  • 2023试用期

登录与注册

后端1+樊伟彤

  • Fan Weitong
  • 2023-10-29
  • 0

~~主打一个。。。寄。。。~~

一.产品说明:(能用就行)

①使用说明:

在postman中输入相应网址(/add /subtract /multiply /divid)和数值进行四则运算

②特殊情况:

  • 切换不同运算时频繁切换key值:pubilc→private
    (虽然没看太懂查的资料,但雀食能行。。。)

  • 输入数据类型有误:。。。这个就要好好说说了。。。

    想法:通过方法判断输入数据类型,用判断语句进行分支(运算or自主报错)当时觉着思路还很河狸

    BUT:!!!用c里面的instanceof直接一行代码爆出来三十个红。。。

    然后查了Java里面的方法 也是instanceof啊 然后按照网上搜的敲 一开始显示“不兼容的类型” 后来整了半天 总是输出返回语句结果...

    最后无力回天。。。寄

  • 数据溢出:看资料cv过来给崩了 寄

二.学习历程:

①培训一spring boot简介

②在b站上搜搜spring boot的框架介绍 但讲的速度慢了点 跳着看又看不懂。。。

③csdn上搜到了Java里instanceof的方法(虽然没用懂)

④从舍友那里知道了切换不同运算时频繁切换key值的方法

总的来说 就是完成了最基本框架 其他的努力了。。。

主程序:

package com.example.demo;

import com.example.demo.service.MainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.NumberFormat;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class three {
    @Autowired
    MainService mainService;//mainservice 服务方法

    @PostMapping("/add")//加
    private double add (@RequestParam double a,@RequestParam double b) {return mainService.add(a, b);}

    @PostMapping("/subtract")//减
    private double subtract (@RequestParam double a,@RequestParam double b){return mainService.subtract(a,b);}

    @PostMapping("/multiply")//乘
    private double multiply (@RequestParam double a,@RequestParam double b){return mainService.multiply(a,b);}

    @PostMapping("/divide")//除
    private double divide (@RequestParam double a,@RequestParam double b){return mainService.divide(a,b);}
}

Service:

package com.example.demo.service;

import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

@Service
public class MainService {
    public double add (double a, double b) {return a + b;}

    public double subtract (double a,double b){return a - b;}

    public  double multiply (double a,double b){return a * b;}

    public  double divide (double a,double b){return a  / b;}
}
Fan Weitong
Fan Weitong
© 2025 软件园学生在线
Theme by Wing