{"id":4112,"date":"2021-11-29T11:00:08","date_gmt":"2021-11-29T03:00:08","guid":{"rendered":"http:\/\/123.57.164.21\/?p=4112"},"modified":"2021-11-29T11:00:08","modified_gmt":"2021-11-29T03:00:08","slug":"cloud-native-%e4%b8%8e-spring-cloud_%e5%85%a5%e9%97%a8_4_crud%e4%b9%8bcontroller","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=4112","title":{"rendered":"Cloud native \u4e0e Spring Cloud_\u5165\u95e8_4_CRUD\u4e4bController"},"content":{"rendered":"\n<h5 class=\"wp-block-heading\">\u7f16\u5199 Controller \u6587\u4ef6<\/h5>\n\n\n\n<h5 class=\"wp-block-heading\"><a href=\"https:\/\/doc-jrecloud-dev.roks-iip-48-2029222ed72d9643e3d07091333056f5-0000.jp-tok.containers.appdomain.cloud\/docs\/intermediate\/crud-controller#\u7f16\u5199-controller-\u6587\u4ef6\">\u200b<\/a><\/h5>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">@RestController\n@RequestMapping(\"\/api\/v1\/products\")\n@Tag(name = \"Product\")\n@Slf4j\npublic class ProductController {\n    @Autowired\n    private ProductService productService;\n\n    @GetMapping\n    @Operation(summary = \"Get a paginated product list. An optional keyword can be provided to narrow the search.\")\n    public PageInfo&lt;Product> list(@Valid ProductSearchInput input) {\n        PageInfo&lt;Product> data = productService.search(input);\n        return data;\n    }\n\n    @GetMapping(\"\/{id}\")\n    @Operation(summary = \"Get detailed information about the product.\")\n    public Product show(@PathVariable Integer id) {\n        Product record = productService.findById(id);\n        return record;\n    }\n\n    @PostMapping\n    @Operation(summary = \"Create a new product.\")\n    public Integer create(@Valid @RequestBody ProductInput record) {\n        Integer id = productService.create(record);\n        return id;\n    }\n\n    @PutMapping(\"\/{id}\")\n    @Operation(summary = \"Update an existing product.\")\n    public void update(@PathVariable Integer id, @RequestBody ProductInput record) {\n        InetUtils.HostInfo host = new InetUtils.HostInfo();\n        log.info(\"server=> {}:{}\", id, host.getHostname(), host.getIpAddress());\n        log.info(\"updating product, id: {}, \", id);\n\n        productService.update(id, record);\n    }\n\n    @DeleteMapping(\"\/{ids}\")\n    @Operation(summary = \"Delete one or more products by id. Multiple ids can be separated with comma.\")\n    public void delete(@PathVariable String ids) {\n        List&lt;String> idList = Arrays.asList(ids.split(\",\"));\n        productService.deleteByIds(idList);\n    }\n\n    @GetMapping(\"\/export-csv\")\n    @Operation(summary = \"Export products to a cvs file.\")\n    public ResponseEntity&lt;InputStreamResource> exportCsv(@Valid ProductSearchInput input) {\n        return productService.exportCsv(input);\n    }\n\n    @PostMapping(value = \"\/import-csv\", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)\n    @Operation(summary = \"Import products from a cvs file.\")\n    public void importCsv(@RequestPart(value = \"file\", required = false) final MultipartFile file) throws Exception {\n        productService.importCsv(file.getInputStream());\n    }\n\n}\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u7f16\u5199 Controller \u6587\u4ef6 \u200b<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/4112"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4112"}],"version-history":[{"count":1,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/4112\/revisions"}],"predecessor-version":[{"id":4113,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/4112\/revisions\/4113"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4112"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4112"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4112"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}