Last active
February 25, 2019 19:08
-
-
Save jonbodner/433d935cc7821382125f819e9dfd3f7f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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