-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelloController.java
More file actions
77 lines (59 loc) · 1.75 KB
/
HelloController.java
File metadata and controls
77 lines (59 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package hello;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import hello.Calculations_repository;
import hello.History;
@Controller
public class HelloController {
private long i=0;
@Autowired
Calculations_repository c;
@RequestMapping(value = "/hello", method = RequestMethod.GET)
public String hello(ModelMap model)
{
return "hello";
}
@RequestMapping(value = "/hello", method = RequestMethod.POST)
//@GetMapping("/hello")
public String cal(ModelMap model, @RequestParam String value, @RequestParam String user_id)
{
perform_calculations p = new perform_calculations();
String error = p.isError(value);
if(error.length()!=0)
{
model.put("value", "invalid expression");
String stry="";
for(History h1:c.findAll())
{
if(user_id.equals(h1.getUser_id()))
stry+=h1.getUser_id()+" "+h1.getQuestion()+" , ";
}
model.put("his",stry);
return "hello";
}
int ans = p.result(value);
model.put("value", value);
model.put("ans",ans);
History h = new History();
h.setQuestion(value);
h.setAnswer(ans);
h.setId(i);
i++;
h.setUser_id(user_id);
c.save(h);
String stry="";
for(History h1:c.findAll())
{
if(user_id.equals(h1.getUser_id()))
stry+=h1.getUser_id()+" "+h1.getQuestion()+" , ";
}
model.put("his",stry);
return "hello";
}
}