springboot中扩展ModelAndView实现net mvc的ActionResult效果

 最近在写spring boot项目,写起来感觉有点繁琐,为了简化spring boot中的Controller开发,对ModelAndView进行简单的扩展,实现net mvc中ActionResult的写法

asp.net core mvc中控制器中提供了IActionResult接口来返回Aciton结果,可以用来返回视图view或者json,当然也可以实现接口返回自定义结果,当时写EasyCMS的时候实现过一个HtmlResult用来返回模板渲染生成的HTML内容,在asp.net core mvc中开发非常简便,那么我们可以看下在asp.net core mvc中的写法

//返回视图 [HttpGet] public IActionResult Index(){ return View(); } //返回json [HttpGet] public IActionResult GetJson(){ return Json(); } //返回字符串 [HttpGet] public IActionResult GetJson(){ return Content(); }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zwfdzw.html