SSM_config配置springmvc.xml模板

1.config配置springmvc.xml



	
	

	
	
	
	

	
	
		
		
		
		
	


2.WEB-INF配置web.xml



	
  				
  springmvcfirst1001
  
  
  
  	springmvc
  	org.springframework.web.servlet.DispatcherServlet
  	
  		contextConfigLocation
  		classpath:springmvc.xml
  	
  
  
  	springmvc
  	*.action
  
  
  
  
    index.html
    index.htm
    index.jsp
    default.html
    default.htm
    default.jsp
  


3.src源码

Controller3代码

package com.app.controller;

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

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

import com.app.po.Items;

/**
 * 
 * @Title ItemsController3.java 
 * @description TODO 
 * @time 2016年9月21日 上午11:26:34 
 * @author xxx
 * @version 1.0 
*
 */
//使用Controller标识 它是一个控制器
@Controller
public class ItemsController3 {
	
	//商品查询列表
	//@RequestMapping实现 对queryItems方法和url进行映射,一个方法对应一个url
	//一般建议将url和方法写成一样
	@RequestMapping("/queryItems")
	public ModelAndView queryItems()throws Exception{
		
		//调用service查找 数据库,查询商品列表,这里使用静态数据模拟
		List itemsList = new ArrayList();
		//向list中填充静态数据
		
		Items items_1 = new Items();
		items_1.setName("联想笔记本");
		items_1.setPrice(6000f);
		items_1.setDetail("ThinkPad T430 联想笔记本电脑!");
		
		Items items_2 = new Items();
		items_2.setName("苹果手机");
		items_2.setPrice(5000f);
		items_2.setDetail("iphone6苹果手机!");
		
		itemsList.add(items_1);
		itemsList.add(items_2);
		
		//返回ModelAndView
		ModelAndView modelAndView =  new ModelAndView();
		//相当 于request的setAttribut,在jsp页面中通过itemsList取数据
		modelAndView.addObject("itemsList", itemsList);
		
		modelAndView.setViewName("items/itemsList");
		
		return modelAndView;
		
	}
	
}


4.模型,注意模型model和模块module有区别

po

import java.util.Date;

public class Items {
	
    private Integer id;       // 商品ID
    private String name;      // 商品姓名
    private Float price;      // 商品价格
    private String pic;       // 商品图片
    private Date createtime;  // 商品时间
    private String detail;    // 商品明细


5

6


你可能感兴趣的:(SSM框架)