实战day09(四)----商品详情页面


一、功能分析

在搜索结果页面点击商品图片或者商品标题,展示商品详情页面。

请求的url:/item/{itemId}

参数:商品id

返回值:String 逻辑视图

业务逻辑:

1、从url中取参数,商品id

2、根据商品id查询商品信息(tb_item)得到一个TbItem对象,缺少images属性,可以创建一个pojo继承TbItem,添加一个getImages方法。在e3-item-web工程中。


创建pojo


package cn.e3mall.item.pojo;

import cn.e3mall.pojo.TbItem;

public class Item extends TbItem{
	
	public String[] getImages() {
		String image2 = this.getImage();
		if (image2 != null && !"".equals(image2)) {
			String[] strings = image2.split(",");
			return strings;
		}
		return null;
	}
	
	public Item() {
		
	}
	
	public Item(TbItem tbItem) {
		this.setBarcode(tbItem.getBarcode());
		this.setCid(tbItem.getCid());
		this.setCreated(tbItem.getCreated());
		this.setId(tbItem.getId());
		this.setImage(tbItem.getImage());
		this.setNum(tbItem.getNum());
		this.setPrice(tbItem.getPrice());
		this.setSellPoint(tbItem.getSellPoint());
		this.setStatus(tbItem.getStatus());
		this.setTitle(tbItem.getTitle());
		this.setUpdated(tbItem.getUpdated());
	}
}

二、dao层

查询tb_item,tb_item_desc两个表,都是单表查询。可以使用逆向工程。

三、Service层

1、根据商品id查询商品信息

参数:商品id

返回值:TbItem

2、根据商品id查询商品描述

参数:商品id

返回值:TbItemDesc


实现类里添加实现代码:

@Override
public TbItemDesc getItemDescById(long itemId) {
	TbItemDesc itemDesc = itemDescMapper.selectByPrimaryKey(itemId);
	return itemDesc;
}

新增了方法,要安装到本地仓库。

e3-manager->run as->maven install

发布服务:


引入服务:


四、Controller

请求的url:/item/{itemId}

参数:商品id

返回值:String 逻辑视图


/**
 * 商品详情页面展示controller
 *
 */
@Controller
public class ItemController {

	@Autowired
	private ItemService itemService;

	@RequestMapping("/item/{itemId}")
	public String showItemInfo(@PathVariable Long itemId, Model model) {
		// 跟据商品id查询商品信息
		TbItem tbItem = itemService.getItemById(itemId);
		// 把TbItem转换成Item对象
		Item item = new Item(tbItem);
		// 根据商品id查询商品描述
		TbItemDesc itemDesc = itemService.getItemDescById(itemId);
		// 把数据传递给页面
		model.addAttribute("item", item);
		model.addAttribute("itemDesc", itemDesc);
		return "item";
	}
}

五、测试

该install的install,该重启的重启。

搜索手机


点击小米手机,进入详情页



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值