当前位置: 首页 > 编程笔记 >

spring boot客户控制器

胥康安
2023-03-14
本文向大家介绍spring boot客户控制器,包括了spring boot客户控制器的使用技巧和注意事项,需要的朋友参考一下

示例

package org.bookmytickets.controller;

import java.util.List;

import org.bookmytickets.model.Customer;
import org.bookmytickets.repository.CustomerRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
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;

@RestController
@RequestMapping(value = "/customer")
public class CustomerController {

    @Autowired
    private CustomerRepository repository;
    
    @GetMapping("")
    public List<Customer> selectAll(){
        List<Customer> customerList = repository.findAll();
        return customerList;
    }
    
    @GetMapping("/{id}")
    public List<Customer> getSpecificCustomer(@PathVariable String id){
        return repository.findById(id);
    }
    
    @GetMapping("/search/lastName/{lastName}")
    public List<Customer> searchByLastName(@PathVariable String lastName){
        return repository.findByLasttName(lastName);
    }

    @GetMapping("/search/firstname/{firstname}")
    public List<Customer> searchByFirstName(@PathVariable String firstName){
        return repository.findByFirstName(firstName);
    }
    
    @PostMapping("")
    public void insert(@RequestBody Customer customer) {
        repository.save(customer);
    }

    @PatchMapping("/{id}")
    public void update(@RequestParam String id, @RequestBody Customer customer) {
        Customer oldCustomer = repository.finedById(id);
        if(customer.getFirstName() != null) {
            oldCustomer.setFristName(customer.getFirstName());
        }
        if(customer.getLastName() != null) {
            oldCustomer.setLastName(customer.getLastName());
        }
        repository.save(oldCustomer);
    }
    
    @DeleteMapping("/{id}")
    public void delete(@RequestParam String id) {
        Customer deleteCustomer = repository.findById(id);
        repository.delete(deleteCustomer);
    }
}

           

 类似资料:
  • 我已经尝试了这篇简单的教程https://spring.io/guides/gs/consource-web-service/,它起作用了。 然后尝试连接到另一个SOAP服务,使用一个附加的和扩展的客户端类。似乎这两个客户机类都使用了相同的-class,这使得我首先添加的一个失败(未知的jaxb-context等)。如何确保客户端类使用正确的-class?

  • 问题内容: 我将移动客户端连接到node.js服务器,并通过xhr-polling运行socket.io。我有两种类型的客户: A型 当由于网络问题(或客户端崩溃)而导致连接中断时,默认的心跳超时时间过长 B型 当此客户端的连接断开时,我需要给它更多的时间来恢复-与服务器断开连接/会话相比,客户端进行恢复更重要 所以我的问题是如何配置(如果可能)来自实际客户端的心跳超时? 问题答案: 据我所知,这

  • 创建Eureka发现客户端和服务器架构。在客户端有userInfo服务CRUD opeartion。它在启动时显示错误。错误是创建在类路径资源[org/springFramework/cloud/autoconfiure/ConfigurationProperty tiesRebinderAutoConfiguration.class]中定义的名为“配置属性Beans”的bean的错误:合并bea

  • 我从这个网站使用了例子。

  • 前台用户控制器和前台控制器类似,只是它需要用户登录后才能访问,要渲染的视图也在前台模板目录(public/themes/)里,要继承cmf\controller\UserBaseController 如: <?php namespace app\portal\controller; use cmf\controller\UserBaseController; class UserControl

  • 前台用户控制器和前台控制器类似,只是它需要用户登录后才能访问,要渲染的视图也在前台模板目录(public/themes/)里,要继承cmf\controller\UserBaseController 如: <?php namespace app\demo\controller; use cmf\controller\UserBaseController; class UserControlle