001-Servlet
Introduction
First assignment of four arithmetic of int and float
Usage
After imported to IDEA, you can run it at localhost:8080/houduanyyds/
By URL
Manually modify the url to get the result
Operation | Path |
---|---|
Plus | /add?a=%s&b=%s |
Minus | /subtract?a=%s&b=%s |
Multiply | /multiply?a=%s&b=%s |
Divide | /divide?a=%s&b=%s |
Plus(point) | /addpoint?a=%f&b=%f |
Minus(point) | /subtractpoint?a=%f&b=%f |
Multiply(point) | /multiplypoint?a=%f&b=%f |
Divide(point) | /dividepoint?a=%f&b=%f |
Error
Floating point calculation只能精确到小数点后五位
Floating point calculation计算时变量后可加f或F,不影响计算结果<
Learning process
Document learning
code
package com.example.firstspringboot1.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 Main1 {
@GetMapping("/houduanyyds")
public String helloWorld(){
return "Hello,world!";
}
@GetMapping("/houduanyyds/add")
public int add (@RequestParam int a, @RequestParam int b){return a + b;
}
@GetMapping("/houduanyyds/subtract")
public int subtract(@RequestParam int a,@RequestParam int b){return a - b;
}
@GetMapping("/houduanyyds/multiply")
public int mutiply(@RequestParam int a,@RequestParam int b){return a * b;
}
@GetMapping("/houduanyyds/divide")
public int divide(@RequestParam int a,@RequestParam int b){return a / b;
}
@GetMapping("/houduanyyds/addpoint")
public float add (@RequestParam float a, @RequestParam float b){return a + b;
}
@GetMapping("/houduanyyds/subtractpoint")
public float subtract(@RequestParam float a,@RequestParam float b){return a - b;
}
@GetMapping("/houduanyyds/multiplypoint")
public float mutiply(@RequestParam float a,@RequestParam float b){return a * b;
}
@GetMapping("/houduanyyds/dividepoint")
public float divide(@RequestParam float a,@RequestParam float b){return a / b;
}
}