資源簡介
利用MVC(SpringMVC+Spring+MyBatis)實現購物車試題,包括完整源代碼和測試數據

代碼片段和文件信息
package?com.neu.controller;
import?java.math.BigDecimal;
import?java.util.HashMap;
import?java.util.List;
import?java.util.Map;
import?javax.servlet.http.HttpSession;
import?org.apache.ibatis.annotations.Param;
import?org.hibernate.validator.internal.util.IgnoreJava6Requirement;
import?org.springframework.beans.factory.annotation.Autowired;
import?org.springframework.stereotype.Controller;
import?org.springframework.ui.Model;
import?org.springframework.web.bind.annotation.ModelAttribute;
import?org.springframework.web.bind.annotation.RequestMapping;
import?org.springframework.web.bind.annotation.RequestParam;
import?com.neu.entity.Good;
import?com.neu.service.GoodService;
@Controller
public?class?GoodController?{
@Autowired
private?GoodService?goodService;
@RequestMapping(“getPaged“)
public?String?getAll(@RequestParam(defaultValue=“1“)?int?pageNumModel?model)?{
int?pageSize?=?3;
List?list?=?goodService.getPaged(pageSize?pageNum);
model.addAttribute(“list“list);
int?count?=?goodService.count();
//計算一共有多少頁
int?pageCount?=?count?%?pageSize?==?0?count/pageSize:count/pageSize+1;
model.addAttribute(“pageCount“?pageCount);
model.addAttribute(“pageNum“?pageNum);
return?“getall“;
}
@RequestMapping(“addToCart“)
public?String?addToCart(Good?goodHttpSession?sessionModel?model)?{
Map?cart?=?(Map)session.getAttribute(“cart“);
if(cart?==?null)?{
cart?=?new?HashMap<>();//創建購物車Map集合
good?=?goodService.getById(good.getId());//從數據庫中查詢商品信息
cart.put(good?1);//向購物車map集合中添加商品
session.setAttribute(“cart“?cart);//向session中添加購物車
}else?{
Integer?n?=?cart.get(good);
if(n?==?null)?{
good?=?goodService.getById(good.getId());//從數據庫中查詢商品信息
cart.put(good?1);
}else?{
cart.put(good?1+n);
}
}
BigDecimal?sum?=?new?BigDecimal(0);
for(Good?g?:?cart.keySet())?{
sum?=?sum.add(g.getPrice().multiply(?new?BigDecimal(cart.get(g))));
}
model.addAttribute(“sum“?sum);
return?“cart“;
}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????1541??2018-06-11?09:08??good_demo\.classpath
?????文件???????1446??2018-06-11?09:08??good_demo\.project
?????文件???????5470??2018-06-11?09:08??good_demo\pom.xm
?????文件????????639??2018-06-11?09:04??good_demo\.settings\.jsdtscope
?????文件????????165??2018-06-11?09:08??good_demo\.settings\org.eclipse.core.resources.prefs
?????文件????????430??2018-06-11?09:08??good_demo\.settings\org.eclipse.jdt.core.prefs
?????文件?????????90??2018-06-11?09:03??good_demo\.settings\org.eclipse.m2e.core.prefs
?????文件????????683??2018-06-11?09:04??good_demo\.settings\org.eclipse.wst.common.component
?????文件????????252??2018-06-11?09:08??good_demo\.settings\org.eclipse.wst.common.project.facet.core.xm
?????文件?????????49??2018-06-11?09:04??good_demo\.settings\org.eclipse.wst.jsdt.ui.superType.container
?????文件??????????6??2018-06-11?09:04??good_demo\.settings\org.eclipse.wst.jsdt.ui.superType.name
?????文件?????????50??2018-06-11?09:04??good_demo\.settings\org.eclipse.wst.validation.prefs
?????文件???????2229??2018-06-11?14:50??good_demo\src\main\java\com\neu\controller\GoodController.java
?????文件???????1813??2018-06-11?14:14??good_demo\src\main\java\com\neu\entity\Good.java
?????文件????????486??2018-06-11?14:33??good_demo\src\main\java\com\neu\mapper\GoodMapper.java
?????文件????????779??2018-06-11?14:33??good_demo\src\main\java\com\neu\mapper\GoodMapper.xm
?????文件????????405??2018-06-11?14:34??good_demo\src\main\java\com\neu\service\GoodService.java
?????文件????????730??2018-06-11?14:34??good_demo\src\main\java\com\neu\service\GoodServiceImpl.java
?????文件???????2273??2018-06-11?09:20??good_demo\src\main\resources\applicationContext.xm
?????文件????????126??2018-06-01?15:03??good_demo\src\main\resources\CustomValidationMessages.properties
?????文件????????294??2018-06-08?16:49??good_demo\src\main\resources\db.properties
?????文件????????401??2018-06-07?09:19??good_demo\src\main\resources\log4j.properties
?????文件???????3876??2018-06-06?09:02??good_demo\src\main\resources\springmvc.xm
?????文件????????905??2018-06-08?16:23??good_demo\src\main\resources\SqlMapConfig.xm
?????文件???????2098??2018-06-11?09:14??good_demo\src\main\webapp\WEB-INF\web.xm
?????文件???????1152??2018-06-11?14:53??good_demo\src\main\webapp\WEB-INF\jsp\cart.jsp
?????文件???????2343??2018-06-11?14:11??good_demo\src\main\webapp\WEB-INF\jsp\getall.jsp
?????文件???????2273??2018-06-11?14:51??good_demo\target\classes\applicationContext.xm
?????文件????????126??2018-06-11?14:51??good_demo\target\classes\CustomValidationMessages.properties
?????文件????????294??2018-06-11?14:51??good_demo\target\classes\db.properties
............此處省略71個文件信息
- 上一篇:文字和圖片水印添加 Winfrom 源碼
- 下一篇:應用數字圖像處理—文字識別
評論
共有 條評論