Skip to content

Instantly share code, notes, and snippets.

@jonbodner
Last active February 25, 2019 19:08
Show Gist options
  • Save jonbodner/433d935cc7821382125f819e9dfd3f7f to your computer and use it in GitHub Desktop.
Save jonbodner/433d935cc7821382125f819e9dfd3f7f to your computer and use it in GitHub Desktop.
package com.example.demo.controller;
import com.example.demo.calculator.Calculator;
import com.example.demo.calculator.CalculatorException;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class CalcController {
private final Calculator calculator;
public CalcController(Calculator calculator) {
this.calculator = calculator;
}
@RequestMapping("/")
public String result(@RequestParam("expression")String expression) {
try {
return Double.toString(calculator.process(expression));
} catch (CalculatorException e) {
return e.getMessage();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment