知乎专栏 |
控制器中调用 Service
package web; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import domain.City; import pojo.ApplicationConfiguration; import repository.CityRepository; import service.TestService; @Controller public class IndexController { @Autowired private TestService testService; @RequestMapping("/service") @ResponseBody public String service() { return testService.helloUser("Neo"); } }