一、專案簡述
功能:網上商城系統,前臺+后臺管理,用戶注冊,登錄, 上哦展示,分組展示,搜索,識訓地址管理,購物車管 理,添加,購買,個人資訊修改,訂單查詢等等,后臺商 品管理,分類管理,庫存管理,訂單管理,用戶管理,信 息、修改等等,
二、專案運行
環境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)
專案技術: JSP +Spring + SpringMVC + MyBatis + html+ css + JavaScript + JQuery + Ajax + layui+ maven等等,







權限控制代碼:
/**
* 基控制器
*/
public class BaseController {
//log4j2
protected Logger logger = LogManager.getLogger(BaseController.class);
//獲取管理員資訊
protected Object checkAdmin(HttpSession session){
Object o = session.getAttribute("adminId");
if(o==null){
logger.info("無管理權限,回傳管理員登陸頁");
return null;
}
logger.info("當前登錄管理員ID:{}",o);
return o;
}
//檢查用戶是否登錄
protected Object checkUser(HttpSession session){
Object o = session.getAttribute("userId");
if(o==null){
logger.info("用戶未登錄");
return null;
}
logger.info("用戶已登錄,用戶ID:{}", o);
return o;
}
}
產品詳情頁代碼:
/**
* 產品詳情頁
*/
@Controller
public class ForeProductDetailsController extends BaseController {
@Resource(name = "productService")
private ProductService productService;
@Resource(name = "userService")
private UserService userService;
@Resource(name = "productImageService")
private ProductImageService productImageService;
@Resource(name = "categoryService")
private CategoryService categoryService;
@Resource(name = "propertyValueService")
private PropertyValueService propertyValueService;
@Resource(name = "propertyService")
private PropertyService propertyService;
@Resource(name = "reviewService")
private ReviewService reviewService;
@Resource(name = "productOrderItemService")
private ProductOrderItemService productOrderItemService;
//轉到前臺天貓-產品詳情頁
@RequestMapping(value = "product/{pid}", method = RequestMethod.GET)
public String goToPage(HttpSession session, Map<String, Object> map,
@PathVariable("pid") String pid /*產品ID*/) {
logger.info("檢查用戶是否登錄");
Object userId = checkUser(session);
if (userId != null) {
logger.info("獲取用戶資訊");
User user = userService.get(Integer.parseInt(userId.toString()));
map.put("user", user);
}
logger.info("獲取產品ID");
Integer product_id = Integer.parseInt(pid);
logger.info("獲取產品資訊");
Product product = productService.get(product_id);
if (product == null || product.getProduct_isEnabled() == 1) {
return "redirect:/404";
}
logger.info("獲取產品子資訊-分類資訊");
product.setProduct_category(categoryService.get(product.getProduct_category().getCategory_id()));
logger.info("獲取產品子資訊-預覽圖片資訊");
List<ProductImage> singleProductImageList = productImageService.getList(product_id, (byte) 0, null);
product.setSingleProductImageList(singleProductImageList);
logger.info("獲取產品子資訊-詳情圖片資訊");
List<ProductImage> detailsProductImageList = productImageService.getList(product_id, (byte) 1, null);
product.setDetailProductImageList(detailsProductImageList);
logger.info("獲取產品子資訊-產品屬性值資訊");
List<PropertyValue> propertyValueList = propertyValueService.getList(new PropertyValue().setPropertyValue_product(product), null);
logger.info("獲取產品子資訊-分類資訊對應的屬性串列");
List<Property> propertyList = propertyService.getList(new Property().setProperty_category(product.getProduct_category()), null);
logger.info("屬性串列和屬性值串列合并");
for (Property property : propertyList) {
for (PropertyValue propertyValue : propertyValueList) {
if (property.getProperty_id().equals(propertyValue.getPropertyValue_property().getProperty_id())) {
List<PropertyValue> property_value_item = new ArrayList<>(1);
property_value_item.add(propertyValue);
property.setPropertyValueList(property_value_item);
break;
}
}
}
logger.info("獲取產品子資訊-產品評論資訊");
product.setReviewList(reviewService.getListByProductId(product_id, null));
if (product.getReviewList() != null) {
for (Review review : product.getReviewList()) {
review.setReview_user(userService.get(review.getReview_user().getUser_id()));
}
}
logger.info("獲取猜你喜歡串列");
Integer category_id = product.getProduct_category().getCategory_id();
Integer total = productService.getTotal(new Product().setProduct_category(new Category().setCategory_id(category_id)), new Byte[]{0, 2});
logger.info("分類ID為{}的產品總數為{}條", category_id, total);
//生成亂數
int i = new Random().nextInt(total);
if (i + 2 >= total) {
i = total - 3;
}
if (i < 0) {
i = 0;
}
List<Product> loveProductList = productService.getList(new Product().setProduct_category(
new Category().setCategory_id(category_id)),
new Byte[]{0, 2},
null,
new PageUtil().setCount(3).setPageStart(i)
);
if (loveProductList != null) {
logger.info("獲取產品串列的相應的一張預覽圖片");
for (Product loveProduct : loveProductList) {
loveProduct.setSingleProductImageList(productImageService.getList(loveProduct.getProduct_id(), (byte) 0, new PageUtil(0, 1)));
}
}
logger.info("獲取分類串列");
List<Category> categoryList = categoryService.getList(null, new PageUtil(0, 3));
map.put("loveProductList", loveProductList);
map.put("categoryList", categoryList);
map.put("propertyList", propertyList);
map.put("product", product);
map.put("guessNumber", i);
map.put("pageUtil", new PageUtil(0, 10).setTotal(product.getProduct_review_count()));
logger.info("轉到前臺-產品詳情頁");
return "fore/productDetailsPage";
}
//按產品ID加載產品評論串列-ajax
@Deprecated
@ResponseBody
@RequestMapping(value = "review/{pid}", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
public String loadProductReviewList(@PathVariable("pid") String pid/*產品ID*/,
@RequestParam Integer index/* 頁數 */,
@RequestParam Integer count/* 行數 */) {
logger.info("獲取產品ID");
Integer product_id = Integer.parseInt(pid);
logger.info("獲取產品評論串列");
List<Review> reviewList = reviewService.getListByProductId(product_id, new PageUtil(index, count));
JSONObject jsonObject = new JSONObject();
jsonObject.put("reviewList", JSONArray.parseArray(JSON.toJSONString(reviewList)));
return jsonObject.toJSONString();
}
//按產品ID加載產品屬性串列-ajax
@Deprecated
@ResponseBody
@RequestMapping(value = "property/{pid}", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
public String loadProductPropertyList(@PathVariable("pid") String pid/*產品ID*/) {
logger.info("獲取產品ID");
Integer product_id = Integer.parseInt(pid);
logger.info("獲取產品詳情-屬性值資訊");
Product product = new Product();
product.setProduct_id(product_id);
List<PropertyValue> propertyValueList = propertyValueService.getList(new PropertyValue().setPropertyValue_product(product), null);
logger.info("獲取產品詳情-分類資訊對應的屬性串列");
List<Property> propertyList = propertyService.getList(new Property().setProperty_category(product.getProduct_category()), null);
logger.info("屬性串列和屬性值串列合并");
for (Property property : propertyList) {
for (PropertyValue propertyValue : propertyValueList) {
if (property.getProperty_id().equals(propertyValue.getPropertyValue_property().getProperty_id())) {
List<PropertyValue> property_value_item = new ArrayList<>(1);
property_value_item.add(propertyValue);
property.setPropertyValueList(property_value_item);
break;
}
}
}
JSONObject jsonObject = new JSONObject();
jsonObject.put("propertyList", JSONArray.parseArray(JSON.toJSONString(propertyList)));
return jsonObject.toJSONString();
}
//加載猜你喜歡串列-ajax
@ResponseBody
@RequestMapping(value = "guess/{cid}", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
public String guessYouLike(@PathVariable("cid") Integer cid, @RequestParam Integer guessNumber) {
logger.info("獲取猜你喜歡串列");
Integer total = productService.getTotal(new Product().setProduct_category(new Category().setCategory_id(cid)), new Byte[]{0, 2});
logger.info("分類ID為{}的產品總數為{}條", cid, total);
//生成亂數
int i = new Random().nextInt(total);
if (i + 2 >= total) {
i = total - 3;
}
if (i < 0) {
i = 0;
}
while (i == guessNumber) {
i = new Random().nextInt(total);
if (i + 2 >= total) {
i = total - 3;
}
if (i < 0) {
i = 0;
break;
}
}
logger.info("guessNumber值為{},新guessNumber值為{}", guessNumber, i);
List<Product> loveProductList = productService.getList(new Product().setProduct_category(
new Category().setCategory_id(cid)),
new Byte[]{0, 2},
null,
new PageUtil().setCount(3).setPageStart(i)
);
if (loveProductList != null) {
logger.info("獲取產品串列的相應的一張預覽圖片");
for (Product loveProduct : loveProductList) {
loveProduct.setSingleProductImageList(productImageService.getList(loveProduct.getProduct_id(), (byte) 0, new PageUtil(0, 1)));
}
}
JSONObject jsonObject = new JSONObject();
logger.info("獲取資料成功!");
jsonObject.put("success", true);
jsonObject.put("loveProductList", JSONArray.parseArray(JSON.toJSONString(loveProductList)));
jsonObject.put("guessNumber", i);
return jsonObject.toJSONString();
}
}
了解詳情可以私聊,感謝大家支持與幫助!
" data-link-title="點擊查看更多java精品專案>">點擊查看更多java精品專案>
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/301746.html
標籤:java
