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

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

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

發(fā)布時(shí)間:2024/4/13 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 15、【 商品管理模块开发】——后台获取商品详情功能开发及PropertiesUtil配置工具,DateTimeUtil时间处理工具开发... 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

1、后臺(tái)獲取商品詳情接口:

在上一篇文章所新建的ProudctManageController類(lèi)中新建下面方法:
*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(),"未登錄,請(qǐng)先登錄");}if(iUserService.checkAdminRole(user).isSuccess()){//增加商品的邏輯方法return iProductService.manageProductDetail(productId);}else {return ServerResponse.createByErrorMessage("當(dāng)前登錄者不是管理員,無(wú)權(quán)限操作");}}

*Service:

//查詢(xún)商品的詳細(xì)信息ServerResponse<ProductDetailVo> manageProductDetail(Integer productId);

*ServiceImpl:

//查詢(xún)商品的詳細(xì)信息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);}

其中用到了selectByPrimaryKey和assembleProductDetailVo這兩個(gè)方法,其中selectByPrimaryKey是使用Mybaties逆向工程生產(chǎn)的方法,根據(jù)productId來(lái)查詢(xún)Product的信息。
下面介紹下assembleProductDetailVo這個(gè)方法
這個(gè)方法是自己封裝的,用戶(hù)返回給前端一個(gè)商品詳情類(lèi),那么為什么要用到這個(gè)封裝類(lèi)呢?因?yàn)槲覀兎祷亟o前端的不僅僅是一個(gè)數(shù)據(jù)表里面的信息,我們返回的多個(gè)表綜合的信息。所以使用的是多表查詢(xún),我們自己封裝了一個(gè)ProductDetailVo類(lèi),來(lái)定義我們需要返回給前端定義的字段。

新建ProductDetailVo類(lèi)

image.png

ProductDetailVo內(nèi)容如下:

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:封裝的方法

//對(duì)返回的商品詳細(xì)信息進(jìn)行封裝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);//默認(rèn)根節(jié)點(diǎn)}else{productDetailVo.setParentCategoryId(category.getParentId());}productDetailVo.setCreateTime(DateTimeUtil.dateToStr(product.getCreateTime()));productDetailVo.setUpdateTime(DateTimeUtil.dateToStr(product.getUpdateTime()));return productDetailVo;}

這一行代碼設(shè)置的是對(duì)應(yīng)的圖片服務(wù)器:下面會(huì)對(duì)這個(gè)作介紹:

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

selectByPrimaryKey方法使用的是逆向工程自動(dòng)生成的方法。

2、PropertiesUtil工具的開(kāi)發(fā):

1、在util包下新建PropertiesUtil類(lèi)


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:

//對(duì)應(yīng)的ftp文件服務(wù)器的相關(guān)配置 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時(shí)間處理工具

1、新建DateTimeUtil工具類(lèi)

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 具體時(shí)間* @param STANDARD_FORMAT 時(shí)間格式* @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、接口測(cè)試

后臺(tái)獲取商品詳情接口測(cè)試

image.png

總結(jié)

以上是生活随笔為你收集整理的15、【 商品管理模块开发】——后台获取商品详情功能开发及PropertiesUtil配置工具,DateTimeUtil时间处理工具开发...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 秋霞午夜视频 | 色综合天天综合网天天看片 | 精品动漫一区二区三区的观看方式 | 精品免费在线观看 | 久久丁香 | 亚洲一区日韩 | 99精品自拍| 久久精品综合视频 | 亚洲精品久久久久久国 | 国产山村乱淫老妇女视频 | 国产夜色精品一区二区av | www.超碰在线| 欧美激情电影一区二区 | 国产精品亚洲专区无码牛牛 | 欧美图片一区二区 | 在线观看免费国产视频 | 国产乱在线 | 中文有码在线 | 色吧av色av | 一区二区三区欧美视频 | 欧美激情免费观看 | 中文字幕永久在线播放 | 久久伊| 日韩欧美在线观看免费 | 69视频国产 | www在线免费观看 | 欧美精品福利 | 第一av | 天天拍夜夜爽 | 色综合天天综合网天天看片 | 久久久久久亚洲 | 好男人www社区 | 国产精品成人自拍 | 狠狠躁夜夜躁av无码中文幕 | 免费在线观看日韩 | 国产欧美精品久久久 | 欧美在线激情 | av黄色天堂 | 成人av一区二区三区在线观看 | 六月婷婷久久 | 天天操天天草 | 三上悠亚一区二区 | 精品久久中文 | 国产91精品看黄网站在线观看 | 日韩一区二区视频在线观看 | 中文字幕日韩在线播放 | 日韩免费精品 | 久久综合91 | 巨大黑人极品videos精品 | 国产精品亚洲欧美 | 黄色一级在线视频 | 天堂网中文字幕 | 九九影院最新理论片 | 亚洲视频在线观看视频 | 九九色在线| 亚洲av永久纯肉无码精品动漫 | 亚洲第一综合网站 | 一级做a爰片毛片 | 国产69久久 | wwwav在线播放 | 成年人色片 | 欧美人与性动交ccoo | 国产成人无码精品久久久性色 | 中文字幕一区二区三区5566 | 久久国产情侣 | 欧美夫妻性生活视频 | 亚洲一区二区视频在线 | 中国少妇做爰全过程毛片 | 黑人一级 | 第四色在线视频 | 美女搞黄在线观看 | 中文字幕国产剧情 | 亚洲色图美腿丝袜 | 九色视频网 | 国产精品亚洲精品 | 亚洲无遮挡 | 久操视频免费观看 | 在线观看欧美国产 | 欧美日韩视频在线 | 激情内射亚洲一区二区三区爱妻 | 日韩喷潮 | 天堂资源最新在线 | 先锋资源网av| 美女一区二区三区视频 | 精品久久久久久无码中文野结衣 | 在线看成人av | 可以直接看av的网址 | 欧美日韩成人在线播放 | 色一情一乱一伦一区二区三区 | 国产精品福利导航 | 91网站永久免费看nba视频 | 尤物国产| 免费看日产一区二区三区 | 黄色片视频免费 | 欧美人与性囗牲恔配 | 精品国产污污免费网站入口 | 中国在线观看免费高清视频播放 | 久久久久久久久久av | 国产一级高清 |