controller层 package wenxin.huahua.controller; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import wenxin.huahua.entity.Customer; import wenxin.huahua.service.CustomerService; @Controller @RequestMapping("customer") public class CustomerController { @Autowired private CustomerService customerService; @RequestMapping("query") public ResponseEntity<Customer> queryCustomerById(@RequestParam(value = "id")Long id){ Customer customer=this.customerService.queryCustomerById(id); if(StringUtils.isEmpty(customer)){ return ResponseEntity.notFound().build(); } return ResponseEntity.ok(customer); } }
service 层
package wenxin.huahua.service; import org.springframework.stereotype.Service; import wenxin.huahua.entity.Customer; public interface CustomerService { /** * 根据id来查询相应的用户信息 */ Customer queryCustomerById(Long