content: package com.us.example.controller;
  
  import javax.servlet.http.HttpServletRequest;
  import java.util.Map;
  
  import org.apache.log4j.Logger;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.http.HttpStatus;
  import org.springframework.http.ResponseEntity;
  import org.springframework.stereotype.Controller;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.bind.annotation.ResponseBody;
  
  
  import com.us.example.service.UserService;
  import com.us.example.util.CommonUtil;
  
  
  @Controller
  @RequestMapping(value = "/users")
  public class UserController {
      private static final Logger logger = Logger.getLogger(UserController.class);
  
      @Autowired
      private UserService userService;
  
  
  
      /**
       * 通过spring data jpa 调用方法
       * api :localhost:8099/users/byname?username=xxx
       * @param request
       * @return
       */
      @RequestMapping(value = "/byname", method = RequestMethod.GET)
      @ResponseBody
      public ResponseEntity<Object> getUser(HttpServletRequest request) {
          Map<String, Object> map = CommonUtil.getParameterMap(request);
          String username = (String) map.get("username");
          return new ResponseEntity<>(userService.getUserByName(username), HttpStatus.OK);
      }
  
  
  }