欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

三步輕松搭建springMVC框架

 更新時間:2017年08月10日 16:20:36   作者:~馳~  
這篇文章主要教大家三步輕松搭建springMVC框架,具有一定的參考價值,感興趣的小伙伴們可以參考一下

一、搭建步驟

1、導入jar包、創(chuàng)建項目包結構

2、在web.xml中配置前端控制器

3、編寫springMvc核心配置文件

4、編寫pojo類和Controller類測試

二、實現(xiàn)

1、導入jar包、創(chuàng)建項目包結構

 2、在web.xml中配置前端控制器

<!-- springMvc前端控制器 -->
<servlet>
<servlet-name>springMvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- 指定springMvc核心配置文件位置
如果沒有指定那么默認就會去"/WEB-INF/+ <servlet-name>標簽中內(nèi)容 + -servlet.xml"中找
例如:"/WEB-INF/springMvc-servlet.xml"
-->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:SpringMvc.xml</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springMvc</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping>

3、編寫springMvc核心配置文件

<?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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">

<!-- 配置@Controller注解掃描 -->
<context:component-scan base-package="cn.it.controller"></context:component-scan>

</beans>

4、編寫pojo類和Controller類測試

pojo類代碼:

package cn.it.pojo;

import java.util.Date;

public class Items {

private Integer id;
private String name;
private Float price;
private String pic;
private Date createtime;
private String detail;

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name == null ? null : name.trim();
}

public Float getPrice() {
return price;
}

public void setPrice(Float price) {
this.price = price;
}

public String getPic() {
return pic;
}

public void setPic(String pic) {
this.pic = pic == null ? null : pic.trim();
}

public Date getCreatetime() {
return createtime;
}

public void setCreatetime(Date createtime) {
this.createtime = createtime;
}

public String getDetail() {
return detail;
}

public void setDetail(String detail) {
this.detail = detail == null ? null : detail.trim();
}
}

Controller類代碼:

package cn.it.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 cn.it.pojo.Items;

@Controller
public class ItemsController {

//@RequestMapping指定URL到請求方法的映射,例如:
@RequestMapping("/itemsList")
public ModelAndView itemsList(){
List<Items>itemList = new ArrayList<Items>();

//商品列表
Items items_1 = new Items();
items_1.setName("聯(lián)想筆記本_3");
items_1.setPrice(6000f);
items_1.setDetail("ThinkPad T430 聯(lián)想筆記本電腦!");

Items items_2 = new Items();
items_2.setName("蘋果手機");
items_2.setPrice(5000f);
items_2.setDetail("iphone6蘋果手機!");

itemList.add(items_1);
itemList.add(items_2);

/*
* 模型和視圖:
* model模型:模型對象中存放了返回給頁面的數(shù)據(jù)
* view視圖:視圖對象中指定了返回的頁面的位置
*/
//創(chuàng)建ModelAndView對象
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("itemList", itemList);
modelAndView.setViewName("/WEB-INF/jsp/itemList.jsp");
return modelAndView;
}
}

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • dubbo如何設置連接zookeeper權限

    dubbo如何設置連接zookeeper權限

    這篇文章主要介紹了dubbo如何設置連接zookeeper權限問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-05-05
  • SpringBoot使用Sa-Token實現(xiàn)登錄認證

    SpringBoot使用Sa-Token實現(xiàn)登錄認證

    本文主要介紹了SpringBoot使用Sa-Token實現(xiàn)登錄認證,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2023-04-04
  • Spring整合Mybatis具體代碼實現(xiàn)流程

    Spring整合Mybatis具體代碼實現(xiàn)流程

    這篇文章主要介紹了Spring整合Mybatis實操分享,文章首先通過介紹Mybatis的工作原理展開Spring整合Mybatis的詳細內(nèi)容,需要的小伙伴可以參考一下
    2022-05-05
  • Spring的組合注解和元注解原理與用法詳解

    Spring的組合注解和元注解原理與用法詳解

    這篇文章主要介紹了Spring的組合注解和元注解原理與用法,結合實例形式詳細分析了spring組合注解和元注解相關功能、原理、配置及使用方法,需要的朋友可以參考下
    2019-11-11
  • 如何在JDK 9中更簡潔使用 try-with-resources 語句

    如何在JDK 9中更簡潔使用 try-with-resources 語句

    本文詳細介紹了自 JDK 7 引入的 try-with-resources 語句的原理和用法,以及介紹了 JDK 9 對 try-with-resources 的改進,使得用戶可以更加方便、簡潔的使用 try-with-resources 語句。,需要的朋友可以參考下
    2019-06-06
  • Java負載均衡服務器實現(xiàn)上傳文件同步

    Java負載均衡服務器實現(xiàn)上傳文件同步

    這篇文章主要介紹了Java負載均衡服務器實現(xiàn)上傳文件同步,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-09-09
  • MyBatis的JdbcType與Oracle、MySql數(shù)據(jù)類型一覽表

    MyBatis的JdbcType與Oracle、MySql數(shù)據(jù)類型一覽表

    這篇文章主要介紹了MyBatis的JdbcType與Oracle、MySql數(shù)據(jù)類型一覽表,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-01-01
  • Java實現(xiàn)帶緩沖的輸入輸出流

    Java實現(xiàn)帶緩沖的輸入輸出流

    本文詳細講解了Java實現(xiàn)帶緩沖的輸入輸出流,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2022-04-04
  • 詳解Spring Batch 輕量級批處理框架實踐

    詳解Spring Batch 輕量級批處理框架實踐

    這篇文章主要介紹了詳解Spring Batch 輕量級批處理框架實踐,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-06-06
  • Spring boot基于ScheduledFuture實現(xiàn)定時任務

    Spring boot基于ScheduledFuture實現(xiàn)定時任務

    這篇文章主要介紹了Spring boot基于ScheduledFuture實現(xiàn)定時任務,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-06-06

最新評論