|
3 | 3 | import java.util.LinkedList; |
4 | 4 | import java.util.List; |
5 | 5 |
|
| 6 | +import javax.ws.rs.PathParam; |
| 7 | +import javax.ws.rs.Consumes; |
| 8 | +import javax.ws.rs.DELETE; |
| 9 | +import javax.ws.rs.GET; |
| 10 | +import javax.ws.rs.POST; |
| 11 | +import javax.ws.rs.PUT; |
| 12 | +import javax.ws.rs.Path; |
| 13 | +import javax.ws.rs.Produces; |
| 14 | + |
6 | 15 | import org.springframework.beans.factory.annotation.Autowired; |
7 | | -import org.springframework.web.bind.annotation.DeleteMapping; |
8 | | -import org.springframework.web.bind.annotation.GetMapping; |
9 | | -import org.springframework.web.bind.annotation.PathVariable; |
10 | | -import org.springframework.web.bind.annotation.PostMapping; |
11 | | -import org.springframework.web.bind.annotation.PutMapping; |
| 16 | +//import org.springframework.web.bind.annotation.DeleteMapping; |
| 17 | +//import org.springframework.web.bind.annotation.GetMapping; |
| 18 | +//import org.springframework.web.bind.annotation.PathVariable; |
| 19 | +//import org.springframework.web.bind.annotation.PostMapping; |
| 20 | +//import org.springframework.web.bind.annotation.PutMapping; |
12 | 21 | import org.springframework.web.bind.annotation.RequestBody; |
13 | 22 | import org.springframework.web.bind.annotation.RestController; |
14 | 23 |
|
15 | 24 | import com.iot.lpnu.services.ToolService; |
16 | 25 | import com.iot.lpnu.tools.TreeTools; |
17 | 26 |
|
| 27 | + |
18 | 28 | @RestController |
| 29 | +@Path("/tool") |
| 30 | +@Consumes("application/json") |
| 31 | +@Produces("application/json") |
19 | 32 | public class ToolController { |
20 | 33 | @Autowired |
21 | 34 | private ToolService toolService; |
22 | 35 |
|
23 | | - @GetMapping("/tool/") |
| 36 | + @GET |
| 37 | + @Path("/") |
| 38 | + @Consumes("application/json") |
| 39 | + @Produces("application/json") |
| 40 | +// @GetMapping("/tool/") |
24 | 41 | public List<TreeTools> getAllTool() { |
25 | 42 | return toolService.findAll(); |
26 | 43 | } |
27 | 44 |
|
28 | | - @GetMapping("/tool/getbyname/{nameString}") |
29 | | - public List<TreeTools> searchByName(@PathVariable String nameString){ |
| 45 | + @GET |
| 46 | + @Path("/getbyname/{nameString}") |
| 47 | + @Consumes("application/json") |
| 48 | + @Produces("application/json") |
| 49 | +// @GetMapping("/tool/getbyname/{nameString}") |
| 50 | + public List<TreeTools> searchByName(@PathParam("nameString") String nameString){ |
30 | 51 | return toolService.findByName(nameString); |
31 | 52 | } |
32 | 53 |
|
33 | | - @GetMapping("/tool/getbyid/{id}") |
34 | | - public TreeTools searchById(@PathVariable int id){ |
| 54 | + @GET |
| 55 | + @Path("/getbyid/{id}") |
| 56 | + @Consumes("application/json") |
| 57 | + @Produces("application/json") |
| 58 | +// @GetMapping("/tool/getbyid/{id}") |
| 59 | + public TreeTools searchById(@PathParam("id") int id){ |
35 | 60 | return toolService.findById(id); |
36 | 61 | } |
37 | 62 |
|
38 | | - @GetMapping("/tool/getbycost/{costInUaPerOne}") |
39 | | - public List<TreeTools> searchByCost(@PathVariable Float costInUaPerOne){ |
| 63 | + @GET |
| 64 | + @Path("/getbycost/{costInUaPerOne}") |
| 65 | + @Consumes("application/json") |
| 66 | + @Produces("application/json") |
| 67 | +// @GetMapping("/tool/getbycost/{costInUaPerOne}") |
| 68 | + public List<TreeTools> searchByCost(@PathParam("costInUaPerOne") Float costInUaPerOne/* @PathVariable Float costInUaPerOne */){ |
40 | 69 | return toolService.findByCostInUaPerOne(costInUaPerOne); |
41 | 70 | } |
42 | 71 |
|
43 | | - @PostMapping("/tool/add") |
| 72 | + @POST |
| 73 | + @Path("/add") |
| 74 | + @Consumes("application/json") |
| 75 | + @Produces("application/json") |
| 76 | +// @PostMapping("/tool/add") |
44 | 77 | public TreeTools addTool(@RequestBody TreeTools treeTools){ |
45 | 78 | return toolService.addTool(treeTools); |
46 | 79 | } |
47 | 80 |
|
48 | | - @PostMapping("/tool/addlist") |
| 81 | + @POST |
| 82 | + @Path("/addlist") |
| 83 | + @Consumes("application/json") |
| 84 | + @Produces("application/json") |
| 85 | +// @PostMapping("/tool/addlist") |
49 | 86 | public List<TreeTools> addListOfTools(@RequestBody LinkedList<TreeTools> list){ |
50 | 87 | return toolService.addListOfTool(list); |
51 | 88 | } |
52 | 89 |
|
53 | | - @PutMapping("/tool/update/{id}") |
54 | | - public TreeTools addListOfTools(@PathVariable Integer id, @RequestBody TreeTools treeTools){ |
| 90 | + @PUT |
| 91 | + @Path("/update/{id}") |
| 92 | + @Consumes("application/json") |
| 93 | + @Produces("application/json") |
| 94 | +// @PutMapping("/tool/update/{id}") |
| 95 | + public TreeTools addListOfTools(@PathParam("id") Integer id, @RequestBody TreeTools treeTools){ |
55 | 96 | return toolService.update(id, treeTools); |
56 | 97 | } |
57 | 98 |
|
58 | | - @DeleteMapping("tool/delete/{id}") |
59 | | - public void delete(@PathVariable int id) { |
| 99 | + @DELETE |
| 100 | + @Path("/delete/{id}") |
| 101 | + @Consumes("application/json") |
| 102 | + @Produces("application/json") |
| 103 | +// @DeleteMapping("tool/delete/{id}") |
| 104 | + public void delete(@PathParam("id") int id) { |
60 | 105 | toolService.delete(id); |
61 | 106 | } |
62 | 107 | } |
0 commit comments