1、后台获取商品详情接口:

在上一篇文章所新建的ProudctManageController类中新建下面方法:
*Controller:

//获取商品详情接口@RequestMapping("get_detail.do")@ResponseBodypublic ServerResponse getDetail(HttpSession session, Integer productId){User user=(User) session.getAttribute(Const.CURRENT_USER);if(user==null){return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(),"未登录,请先登录");}if(iUserService.checkAdminRole(user).isSuccess()){//增加商品的逻辑方法return iProductService.manageProductDetail(productId);}else {return ServerResponse.createByErrorMessage("当前登录者不是管理员,无权限操作");}}

*Service:

    //查询商品的详细信息ServerResponse<ProductDetailVo> manageProductDetail(Integer productId);

*ServiceImpl:

//查询商品的详细信息public ServerResponse<ProductDetailVo> manageProductDetail(Integer productId){if(productId==null){return ServerResponse.createByErrorCodeMessage(ResponseCode.ILLEGAL_ARGUMENT.getCode(),ResponseCode.ILLEGAL_ARGUMENT.getDesc());}Product product=productMapper.selectByPrimaryKey(productId);if(product==null){return ServerResponse.createByErrorMessage("商品已下架或者删除");}ProductDetailVo productDetailVo=assembleProductDetailVo(product);return  ServerResponse.createBySuccess(productDetailVo);}

其中用到了selectByPrimaryKeyassembleProductDetailVo这两个方法,其中selectByPrimaryKey是使用Mybaties逆向工程生产的方法,根据productId来查询Product的信息。
下面介绍下assembleProductDetailVo这个方法
这个方法是自己封装的,用户返回给前端一个商品详情类,那么为什么要用到这个封装类呢?因为我们返回给前端的不仅仅是一个数据表里面的信息,我们返回的多个表综合的信息。所以使用的是多表查询,我们自己封装了一个ProductDetailVo类,来定义我们需要返回给前端定义的字段。

新建ProductDetailVo

image.png

ProductDetailVo内容如下:

package com.mmall.vo;import java.math.BigDecimal;public class ProductDetailVo {private Integer id;private Integer categoryId;private String name;private String subtitle;private String mainImage;private String subImages;private String detail;private BigDecimal price;private Integer stock;private Integer status;private String createTime;private String updateTime;private String imageHost;private Integer parentCategoryId;public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public Integer getCategoryId() {return categoryId;}public void setCategoryId(Integer categoryId) {this.categoryId = categoryId;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getSubtitle() {return subtitle;}public void setSubtitle(String subtitle) {this.subtitle = subtitle;}public String getMainImage() {return mainImage;}public void setMainImage(String mainImage) {this.mainImage = mainImage;}public String getSubImages() {return subImages;}public void setSubImages(String subImages) {this.subImages = subImages;}public String getDetail() {return detail;}public void setDetail(String detail) {this.detail = detail;}public BigDecimal getPrice() {return price;}public void setPrice(BigDecimal price) {this.price = price;}public Integer getStock() {return stock;}public void setStock(Integer stock) {this.stock = stock;}public Integer getStatus() {return status;}public void setStatus(Integer status) {this.status = status;}public String getCreateTime() {return createTime;}public void setCreateTime(String createTime) {this.createTime = createTime;}public String getUpdateTime() {return updateTime;}public void setUpdateTime(String updateTime) {this.updateTime = updateTime;}public String getImageHost() {return imageHost;}public void setImageHost(String imageHost) {this.imageHost = imageHost;}public Integer getParentCategoryId() {return parentCategoryId;}public void setParentCategoryId(Integer parentCategoryId) {this.parentCategoryId = parentCategoryId;}
}

assembleProductDetailVo:封装的方法

 //对返回的商品详细信息进行封装private ProductDetailVo assembleProductDetailVo(Product product){ProductDetailVo productDetailVo=new ProductDetailVo();productDetailVo.setId(product.getId());productDetailVo.setSubtitle(product.getSubtitle());productDetailVo.setPrice(product.getPrice());productDetailVo.setMainImage(product.getMainImage());productDetailVo.setSubImages(product.getSubImages());productDetailVo.setCategoryId(product.getCategoryId());productDetailVo.setDetail(product.getDetail());productDetailVo.setName(product.getName());productDetailVo.setStatus(product.getStatus());productDetailVo.setStock(product.getStock());productDetailVo.setImageHost(PropertiesUtil.getProperty("ftp.server.http.prefix","http://img.happymmall.com/"));Category category=categoryMapper.selectByPrimaryKey(product.getCategoryId());if(category==null){productDetailVo.setParentCategoryId(0);//默认根节点}else{productDetailVo.setParentCategoryId(category.getParentId());}productDetailVo.setCreateTime(DateTimeUtil.dateToStr(product.getCreateTime()));productDetailVo.setUpdateTime(DateTimeUtil.dateToStr(product.getUpdateTime()));return productDetailVo;}

这一行代码设置的是对应的图片服务器:下面会对这个作介绍:

 productDetailVo.setImageHost(PropertiesUtil.getProperty("ftp.server.http.prefix","http://img.happymmall.com/"));

selectByPrimaryKey方法使用的是逆向工程自动生成的方法。

2、PropertiesUtil工具的开发:

1、在util包下新建PropertiesUtil

PropertiesUtil:

package com.mmall.util;import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;/*** Created by geely*/
public class PropertiesUtil {private static Logger logger = LoggerFactory.getLogger(PropertiesUtil.class);private static Properties props;static {String fileName = "mmall.properties";props = new Properties();try {props.load(new InputStreamReader(PropertiesUtil.class.getClassLoader().getResourceAsStream(fileName),"UTF-8"));} catch (IOException e) {logger.error("配置文件读取异常",e);}}public static String getProperty(String key){String value = props.getProperty(key.trim());if(StringUtils.isBlank(value)){return null;}return value.trim();}public static String getProperty(String key,String defaultValue){String value = props.getProperty(key.trim());if(StringUtils.isBlank(value)){value = defaultValue;}return value.trim();}}
    String fileName = "mmall.properties";

这行代码所指的就是下文中新建的mmal.properties配置文件 。

2、resouces目录下新建mmal.properties配置文件

image.png

mmal.properties:

//对应的ftp文件服务器的相关配置
ftp.server.ip=127.0.0.1
ftp.user=admin
ftp.pass=admin
ftp.server.http.prefix=http://image.imooc.com/alipay.callback.url=http://erjq8u.natappfree.cc/order/alipay_callback.dopassword.salt = geelysdafaqj23ou89ZXcj@#$@#$#@KJdjklj;D../dSF.,

3、DateTimeUtil时间处理工具

1、新建DateTimeUtil工具类

DateTimeUtil:

package com.mmall.util;import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;import java.util.Date;public class DateTimeUtil {//joda-time//str->date//date->strpublic static final String STANDARD_FORMAT="yyyy-MM-dd HH:mm:ss";public  static Date strToDate(String dateTimeStr,String formatStr){DateTimeFormatter dateTimeFormatter=DateTimeFormat.forPattern(formatStr);DateTime dateTime=dateTimeFormatter.parseDateTime(dateTimeStr);return dateTime.toDate();}public static String dateToStr(Date date,String formatStr){if(date==null){return StringUtils.EMPTY;}DateTime dateTime=new DateTime(date);return dateTime.toString(formatStr);}/**** @param dateTimeStr 具体时间* @param STANDARD_FORMAT  时间格式* @return*/public  static Date strToDate(String dateTimeStr){DateTimeFormatter dateTimeFormatter=DateTimeFormat.forPattern(STANDARD_FORMAT);DateTime dateTime=dateTimeFormatter.parseDateTime(dateTimeStr);return dateTime.toDate();}public static String dateToStr(Date date){if(date==null){return StringUtils.EMPTY;}DateTime dateTime=new DateTime(date);return dateTime.toString(STANDARD_FORMAT);}/* public static void main(String[] args) {System.out.println(DateTimeUtil.dateToStr(new Date(),"yyyy-MM-dd HH:mm:ss"));System.out.println(DateTimeUtil.strToDate("2016-02-09 11:45:28","yyyy-MM-dd HH:mm:ss"));}*/
}

4、接口测试

后台获取商品详情接口测试

image.png

15、【 商品管理模块开发】——后台获取商品详情功能开发及PropertiesUtil配置工具,DateTimeUtil时间处理工具开发...相关推荐

  1. 9.1黑马Vue电商后台管理系统商品管理模块完善:编辑商品的功能

    在原视频中,老师跳过了这个功能,我觉得自己去实现也可以锻炼自己,于是自己补充了编辑功能 同用户管理,权限管理等之前各个模块的编辑功能不同,因为商品具有很多可编辑的选项,所以选择像添加商品一样,单独放在 ...

  2. Java实战 SpringBoot 网站开发 留言管理、网站后台留言管理模块、后台网站用户运营数据管理开发。

    <QA不加班 > 前言 Java SpringBoot 网站实战开发 留言管理.网站后台留言管理模块.后台网站用户运营数据管理开发. Java 网站开发网站运营后台管理和用户留言板功能后端 ...

  3. mmall 学习笔记--分类管理模块,商品管理模块,购物车模块,收货地址模块,支付模块,订单管理模块,云服务器线上部署,自动发布,

    ()数据库配置 常见语句 Create table 'my_table'( int id not null auto_increment ) () 建表的时候出现text,bigInt,decimal ...

  4. Android开发——后台获取用户点击位置坐标(可获取用户支付宝密码)

    1. getevent命令 我们首先是根据adb shell getevent命令获取到被点击位置的信息. 这里要说明的是,不同的手机手机获得的点击输出是不一样的.以我的真机为例,输出如下 本文原创, ...

  5. 【实战】7-2 商品管理模块开发测试

    前言 找完工作以后感觉一段时间失去了学习的激情,再加上毕业论文的工作,懒散拖沓了好久才开始继续我的项目学习.其实这些内容吧,你说难那是一点也不难,重要的在于处理业务的经验,防患漏洞的经验,以及隐藏在项 ...

  6. 17、【 商品管理模块开发】——后台商品图片的springmvc和富文本上传以及ftp文件服务器的开发...

    1.FTP文件服务器的搭建: 软件下载:ftpserver: image.png 浏览器访问:ftp://127.0.0.1/ image.png 点击任意一个文件,就可以看到我们图片啦,前提是前面指 ...

  7. java菜单管理模块_后台管理系统-菜单管理模块

    1 菜单管理页面设计 1.1 业务设计 菜单管理又称为资源管理,是系统资源对外的表现形式.本模块主要是实现对菜单进行添加.修改.查询.删除等操作.CREATE TABLE `sys_menus` ( ...

  8. php mysql商品管理_PHP基础示例:商品信息管理系统v1.1[转]

    实现目标:使用php和mysql写一个商品信息管理系统,并带有购物车功能 一.创建数据库和表 1.创建数据库和表:demodb 2.创建表格:goods 字段:商品编号,商品名称,商品类型,商品图片, ...

  9. SSM快速开发超市管理系统 用户详情功能实现(二)

    开发工具:idea Maven管理 框架SSM 数据库:mysql Mybatis:TKMybatis 在前面的博客中也已经介绍了框架搭建以及登录.验证码.模糊查询等操作,没有看的大家可以去翻之前的博 ...

最新文章

  1. eoLinker AMS 专业版V3.3发布:分享项目可以测试并选择分享内容等
  2. 用XML反序列化快速完成ASP.NET配置文件
  3. 服务器漏洞处理_wildfly禁用https和8443端口
  4. AI (1)---没错,AR其实也是AI
  5. matlab连通域分割_MATLAB车牌识别之7个字符切割浅谈【抽丝剥茧】
  6. php框架 dirname,PHP目录函数basename()与dirname()
  7. Gerrit 服务搭建和升级详解(包括 H2 数据库迁移 MySQL 步骤)
  8. python GUI初步
  9. java中递归算法_java中递归算法是什么怎么算的?
  10. html页面改成wap页面,wap网页怎么制作 这五大常见问题你要了解一下了!
  11. 操作系统课程设计任务书
  12. 金仓数据库KingbaseES数据库概念(六)--数据库对象管理
  13. MYSQL之STRAIGHT_JOIN
  14. 使用Kinect V2进行录制视频
  15. 高端大气的艺术海报的ps教程
  16. Mac系统brew install 安装报错 Error: Failure while executing
  17. 每个程序员必须掌握的常用英语词汇(建议收藏)
  18. 结构光三维重建基本原理
  19. Symbian程序安装不成功的解决方法
  20. 深入理解LightGBM

热门文章

  1. Aspose.cell生成表格
  2. CSS-带尖角的对话框
  3. CMD-NET命令详解、NET命令大全(转)
  4. Discuz! $_DCACHE数组变量覆盖漏洞
  5. Cisco IOS防火墙的安全规则和配置方案
  6. 利用license机制来保护Java软件产品的安全
  7. 再高深的 Python 面试难题,这门课都给你整得明明白白!
  8. apache配置证书后 tomcat无法访问_给你的项目配置个https吧
  9. jumpserver-v2.9.2离线安装
  10. SpringSecurity集中式整合之授权操作