软件园学生在线

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

登录与注册

【后端一】周泽天

  • 周泽天
  • 2022-10-14
  • 0

培训⼀:基于 Spring boot 的简单 REST API

一 四则运算

基于double的四则运算

二使用方法

在IDEA中导入以后在localhost:8080中运行

三URI

手动打出URI来获得结果

操作 运行
Plus localhost:8080/plus?a1=%&a2=%
Minus localhost:8080/minus?a1=%&a2=%
Multiple localhost:8080/multiple?a1=%&a2=%
Divide localhost:8080/divide?a1=%&a2=%

四学习心得

1学习快捷键 CTRL+r 全部把int 换为double
2成功实现在实数范围内的四则运算
3写了一点前端的窗口但是还无法实现前后端传参

五代码块

package com.example.demo.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class MainController {

    @GetMapping("/")
    public String helloWorld() {
        return "Hello,world";
    }
@GetMapping("/Plus")
    public double Plus (@RequestParam double a1, @RequestParam  double b2) {
        return a1 + b2;
    }
    @GetMapping("/Minus")
    public double Minus (@RequestParam double a1,@RequestParam double a2) {
         return a1 - a2 ;
    }
    @GetMapping("/Divide")
    public double Divide (@RequestParam double a1,@RequestParam double a2) {

        return a1 / a2;
    }
    @GetMapping("/Multiple")
    public double Multiple (@RequestParam double a1,@RequestParam double a2) {
        return a1 * a2;
    }
}

六 小前端

<!DOCTYPE html>
<html >
<head>
    <meta charset="UTF-8">
    <title>输入</title>
</head>
<body>
<p>a1:<input type="text" value=" " ></p>
<button type="button">=</button>
<button>-</button>
<button>*</button>
<button>/</button>
<p>a2:<input type="text" value=" " ></p>
<p>=:<input type="text" value=" " ></p>
</body>
</html>
周泽天
周泽天
© 2025 软件园学生在线
Theme by Wing