中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

基于注解的spring MVC程序

2018-07-20    來(lái)源:open-open

容器云強(qiáng)勢(shì)上線!快速搭建集群,上萬(wàn)Linux鏡像隨意使用

在上一篇博文的基礎(chǔ)上進(jìn)行修改

修改配置文件

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    	http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
    	http://www.springframework.org/schema/context
    	http://www.springframework.org/schema/context/spring-context-4.2.xsd
    	">
   

	<!-- 自動(dòng)裝配bean -->
   <!-- 自動(dòng)檢測(cè)bean -->
	<context:component-scan
		base-package="com.hellospringmvc"
	></context:component-scan>


	<!-- 配置處理器映射器 -->
	<!-- 使用RequestMappingHandlerMapping需要在Handler 中使用@controller標(biāo)識(shí)此類是一個(gè)控制器,使用@requestMapping指定Handler方法所對(duì)應(yīng)的url -->
	<bean
		class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping">
	</bean>
	
	<!-- 配置處理器適配器 -->
	<!-- RequestMappingHandlerAdapter,不要求Handler實(shí)現(xiàn)任何接口,它需要和RequestMappingHandlerMapping注解映射器配對(duì)使用,主要解析Handler方法中的形參 -->
	<bean
		class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"/>
	
	
	<!-- 配置視圖解析器
		要求將jstl的包加到classpath
	 -->
   <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
      <property name="prefix" value="/WEB-INF/" />
      <property name="suffix" value=".jsp" />
   </bean>

</beans>

修改類
package com.hellospringmvc;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class HelloController {
 
	@RequestMapping("/queryItems")
	public ModelAndView queryItems(){
		
		//商品列表
		List<Item> itemsList = new ArrayList<Item>();
		
		Item items_1 = new Item();
		items_1.setName("聯(lián)想筆記本");
		items_1.setPrice(6000f);
		items_1.setDetail("ThinkPad T430 聯(lián)想筆記本電腦!");
		
		Item items_2 = new Item();
		items_2.setName("蘋果手機(jī)");
		items_2.setPrice(5000f);
		items_2.setDetail("iphone6蘋果手機(jī)!");
		
		itemsList.add(items_1);
		itemsList.add(items_2);
		
		//創(chuàng)建modelAndView準(zhǔn)備填充數(shù)據(jù)、設(shè)置視圖
		ModelAndView modelAndView = new ModelAndView();
		
		//填充數(shù)據(jù)
		modelAndView.addObject("itemsList", itemsList);
		//視圖
		modelAndView.setViewName("helloController");
		
		return modelAndView;
	}


}


標(biāo)簽:

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請(qǐng)聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請(qǐng)與原作者聯(lián)系。

上一篇:7個(gè)有用的jQuery代碼片段分享

下一篇:Javascript 操作select控件大全(新增、修改、刪除、選中、清空、判斷存在等)