首页 > 图灵资讯 > java面试题>正文

金三银四精选面试题-SpringBoot的四种Handler类型

2023-11-14 10:35:58

SpringBoot的四种Handler类型

1、@Controller+@RequestMapping
@RestController
public class ZhouyuController {
@GetMapping("/test")
public string test() {
return "zhouyu";
}

}

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;
}
}
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
@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);
}

}

 

上一篇 金三银四精选面试题-Mysql中九种索引失效场景分析
下一篇 金三银四精选面试题-什么是浅拷贝和深拷贝?

文章素材均来源于网络,如有侵权,请联系管理员删除。