-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCarmodelController.java
42 lines (30 loc) · 1.01 KB
/
CarmodelController.java
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
package hello;
import java.util.List;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class CarmodelController {
@RequestMapping(value = "/carmodels", method = RequestMethod.GET)
public List<Carmodel> carmodelGet() {
return Carshop.carmodels;
}
@RequestMapping(value = "/carmodels", method = RequestMethod.POST)
public Carmodel carmodelPost(
@RequestBody Carmodel car) {
int id = getMax(Carshop.carmodels)+1;
car.id =id;
Carshop.carmodels.add(car);
return car;
}
public int getMax(List<Carmodel> list){
int max = Integer.MIN_VALUE;
for(int i=0; i<list.size(); i++){
if(list.get(i).getid() > max){
max = list.get(i).getid();
}
}
return max;
}
}