重慶分公司,新征程啟航
為企業提供網站建設、域名注冊、服務器等服務
為企業提供網站建設、域名注冊、服務器等服務
這篇文章主要講解了SpringMVC后端怎么返回數據到前端,內容清晰明了,對此有興趣的小伙伴可以學習一下,相信大家閱讀完之后會有幫助。
1.返回ModelAndView對象(.jsp)
controller代碼:
package controller; import java.util.List; import javax.annotation.Resource; import model.Comment; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.stereotype.Service; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; import service.CommentService; @Controller //@RequestMapping("comment") public class CommentController { @Resource private CommentService commentService; @RequestMapping(value="showComments") public ModelAndView test(){ ModelAndView mav = new ModelAndView(); Listcomments = commentService.selectAllComment(); for(Comment com:comments){ System.out.println(com.getC_text()); } mav.addObject("msg",comments); mav.setViewName("textIndex.jsp"); return mav; } }
另外有需要云服務器可以了解下創新互聯建站www.cdcxhl.com,海內外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業上云的綜合解決方案,具有“安全穩定、簡單易用、服務可用性高、性價比高”等特點與優勢,專為企業上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。