日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

002_注解开发

發布時間:2025/4/17 编程问答 57 豆豆
生活随笔 收集整理的這篇文章主要介紹了 002_注解开发 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1. 處理器映射器注解配置

<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>

2. 處理器適配器注解配置

<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter" />

3. 映射器與適配器必需配套使用

3.1. 如果映射器使用了推薦的RequestMappingHandlerMapping, 適配器也必需使用推薦的RequestMappingHandlerAdapter。

4. 注解驅動

<!-- 注解驅動配置, 代替映射器與適配器的單獨配置, 同時支持json響應(推薦使用) --> <mvc:annotation-driven />

5. 視圖解析器

<!-- 配置視圖解析器 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><!-- 配置視圖響應的前綴 --><property name="prefix" value="/WEB-INF/jsp/" /><!-- 配置視圖響應的后綴 --><property name="suffix" value=".jsp" /> </bean>

6. 例子

6.1. 新建一個名為SpringMVCAnnotation的Web工程, 同時拷入相關jar包

6.2. 新建Item.java

package com.lywgames.domain;import java.io.Serializable; import java.util.Date;public class Item implements Serializable{private static final long serialVersionUID = 1L;// 商品idprivate Integer id;// 商品名稱private String name;// 商品價格private Double price;// 商品創建時間private Date createtime;// 商品描述private String detail;public Item() { }public Item(Integer id, String name, Double price, Date createtime, String detail) {this.id = id;this.name = name;this.price = price;this.createtime = createtime;this.detail = 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;}public Double getPrice() {return price;}public void setPrice(Double price) {this.price = price;}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;} }

6.3. 新建ItemAction.java

package com.lywgames.web.action;import java.util.ArrayList; import java.util.Date; import java.util.List; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; import com.lywgames.domain.Item;@Controller public class ItemAction {@RequestMapping("itemList")public ModelAndView findAllProducts() {ModelAndView mav = new ModelAndView();List<Item> itemList = new ArrayList<Item>();itemList.add(new Item(1, "冰箱", 1999.0, new Date(), "保鮮。"));itemList.add(new Item(2, "電腦", 8888.0, new Date(), "網上沖浪"));itemList.add(new Item(3, "洗衣機", 4000.0, new Date(), "從此不用手。"));itemList.add(new Item(4, "空調", 2600.0, new Date(), "冬天制熱, 夏天制冷。"));itemList.add(new Item(5, "液晶電視", 20000.0, new Date(), "曲面屏幕"));//設置商品數據mav.addObject("itemList", itemList);//設置視圖名字mav.setViewName("itemList");return mav;} }

6.4. 在src下, 編寫springmvc.xml

6.5. 在web.xml里配置請求路徑攔截、SpringMVC的前端控制器和加載SpringMVC的核心配置文件。

6.6. 編寫index.jsp

6.7. 編寫itemList.jsp

6.8. 運行項目

6.9. 點擊查詢所有商品

總結

以上是生活随笔為你收集整理的002_注解开发的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。