1、@Controller+@RequestMapping
@RestController
public class ZhouyuController {
public class ZhouyuController {
}
2、Controller接口/**
* 作者:周瑜大都督
*/
@Component("/beanNameController")
public class ZhouyuBeanNameController implements Controller {
@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
response.getWriter().println("ZhouyuBeanNameController");
return null;
}
* 作者:周瑜大都督
*/
@Component("/beanNameController")
public class ZhouyuBeanNameController implements Controller {
@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
response.getWriter().println("ZhouyuBeanNameController");
return null;
}
}
3、HttpRequestHandler
/**
* 作者:周瑜大都督
*/
@Component("/beanNameHandler")
public class ZhouyuBeanNameHandler implements HttpRequestHandler {
@Override
public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws IOException {
response.getWriter().println("ZhouyuBeanNameHandler");
}
}
4、RouterFunction
* 作者:周瑜大都督
*/
@Component("/beanNameHandler")
public class ZhouyuBeanNameHandler implements HttpRequestHandler {
@Override
public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws IOException {
response.getWriter().println("ZhouyuBeanNameHandler");
}
}
@SpringBootApplication
public class MyApplication {
@Bean
public RouterFunction<ServerResponse> routerFunction(){
return route()
.GET("/getUserName", request -> ServerResponse.ok().body("zhouyu"))
.GET("/getUserAge", request -> ServerResponse.ok().body("88"))
.build();
}
public static void main(String[] args) {
SpringApplication.run(MyApplication.class);
}
}
public class MyApplication {
@Bean
public RouterFunction<ServerResponse> routerFunction(){
return route()
.GET("/getUserName", request -> ServerResponse.ok().body("zhouyu"))
.GET("/getUserAge", request -> ServerResponse.ok().body("88"))
.build();
}
public static void main(String[] args) {
SpringApplication.run(MyApplication.class);
}
}