當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
设置SpringMVC默认首页启动
生活随笔
收集整理的這篇文章主要介紹了
设置SpringMVC默认首页启动
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
前端控制器代碼如下
//控制前臺頁面的控制器
@Controller
@RequestMapping("/front")
public class FrontController {
//從這里去首頁;所有的操作都是從控制器出去的;
@RequestMapping("/index")public ModelAndView index(){//模型視圖對象,里面可以存放數據到model,還可以存放視圖信息到viewModelAndView mv=new ModelAndView();List<Category> cateList=cateService.search();mv.addObject("cateList",cateList);//shopList:所有商品信息;把查詢的所有數據,給誰了?//<泛型>:就是用來指定List集合里面具體的類型;因為List它里面可以放任意類型,現在給它指定一個Shop(商品)類型List<Shop>shopList=shopService.search();mv.addObject("shopList",shopList); //數據在shopList,存放到model,一個變量叫shopListmv.setViewName("../../index");//../表示上一級;注意系統默認解析路徑是WEB/INF/jsp/return mv;}
需要設置web.xml文件的springmvc配置如下:
?
<servlet><servlet-name>springmvc</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value>/WEB-INF/spring-config.xml</param-value></init-param><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>springmvc</servlet-name><url-pattern>/front/index</url-pattern></servlet-mapping>并且設置
<welcome-file-list><welcome-file>front/index</welcome-file></welcome-file-list>最終效果:
?
總結
以上是生活随笔為你收集整理的设置SpringMVC默认首页启动的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 高仿国美在线底部代码实现
- 下一篇: H5 postMessage跨文档消息传