Skip to content

Commit

Permalink
添加对搜索引擎的支持
Browse files Browse the repository at this point in the history
  • Loading branch information
RhysXia committed Mar 12, 2018
1 parent 5c37286 commit bbed92b
Show file tree
Hide file tree
Showing 30 changed files with 397 additions and 219 deletions.
33 changes: 12 additions & 21 deletions db/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ DROP TABLE IF EXISTS `comment`;
DROP TABLE IF EXISTS `cart_product`;
DROP TABLE IF EXISTS `admin`;
DROP TABLE IF EXISTS `address`;
DROP TABLE IF EXISTS `product_description`;
DROP TABLE IF EXISTS `index_product`;
DROP TABLE IF EXISTS `index_slider`;

Expand Down Expand Up @@ -122,6 +121,8 @@ CREATE TABLE `product` (
COMMENT '评论数',
sale_date DATETIME DEFAULT NULL
COMMENT '上架时间',
description TEXT DEFAULT NULL
COMMENT '详情',
KEY `category_id`(`category_id`),
PRIMARY KEY `id`(`id`)
)
Expand Down Expand Up @@ -237,16 +238,6 @@ CREATE TABLE `address` (
)
COMMENT '地址表';

CREATE TABLE `product_description` (
product_id INT(20) NOT NULL
COMMENT '商品id',
description TEXT NOT NULL
COMMENT '商品详情',
KEY `product_id`(`product_id`),
PRIMARY KEY `product_id`(`product_id`)
)
COMMENT '商品评论信息表';


CREATE TABLE `index_product` (

Expand All @@ -262,14 +253,14 @@ CREATE TABLE `index_product` (

CREATE TABLE `index_slider` (

`id` INT(20) NOT NULL AUTO_INCREMENT
COMMENT 'id',
`title` VARCHAR (32)
COMMENT '图片标题',
`image_url` VARCHAR (512) NOT NULL
COMMENT '轮播图url',
`jump_url` VARCHAR (512)
COMMENT '跳转url',
PRIMARY KEY `id`(`id`)
`id` INT(20) NOT NULL AUTO_INCREMENT
COMMENT 'id',
`title` VARCHAR(32)
COMMENT '图片标题',
`image_url` VARCHAR(512) NOT NULL
COMMENT '轮播图url',
`jump_url` VARCHAR(512)
COMMENT '跳转url',
PRIMARY KEY `id`(`id`)
)
COMMENT '主页轮播图表';
COMMENT '主页轮播图表';
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.rhinoceros.mall.admin.controller;

import com.rhinoceros.mall.core.po.Product;
import com.rhinoceros.mall.core.po.ProductDescription;
import com.rhinoceros.mall.core.query.PageQuery;
import com.rhinoceros.mall.service.service.ProductService;
import com.rhinoceros.mall.web.support.web.annotation.PageDefault;
Expand All @@ -25,8 +24,9 @@ public class ProductController {
private ProductService productService;

/**
*定义方法找到商品并转换为json格式返回
* 定义方法找到商品并转换为json格式返回
* ?page=1&size=10&sort=saleNum,DESC/ASC&sort=price,DESC
*
* @param pageQuery
* @param categoryId
* @return
Expand All @@ -48,13 +48,4 @@ public String showProduct() {
return "include/product";
}

/**
* 通过回传的id查找商品描述信息
*/
@ResponseBody
@RequestMapping("/description.json")
public ProductDescription findDescriptionById(@RequestParam(value="id") Long id){
return productService.findDescriptionById(id);
}

}
9 changes: 2 additions & 7 deletions mall-admin/src/main/webapp/WEB-INF/jsp/include/product.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,8 @@
$("#productCategory").textbox('setText', category.name)
}
})
$.ajax({
url: '${pageContext.request.contextPath}/product/description.json?id=' + row.id,
method: 'get',
success: function (productDescription) {
$("#productDescription").texteditor('setValue', productDescription.description)
}
})
$("#productDescription").texteditor('setValue', row.description)
$("#productName").textbox('setText', row.name)
$("#productPrice").textbox('setText', row.price)
$("#productDiscount").textbox('setText', row.discount)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public enum UserStatus {
/**
* 未激活
*/
UNACTIVATE,
UNACTIVATED,

/**
* 激活
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,9 @@ public class Product {
* 上架时间
*/
private Date saleDate;

/**
* 商品描述信息
*/
private String description;
}

This file was deleted.

24 changes: 3 additions & 21 deletions mall-core/src/main/java/com/rhinoceros/mall/core/vo/ProductVo.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
/* created at 3:27 PM 2/28/2018 */

import com.rhinoceros.mall.core.po.Product;
import com.rhinoceros.mall.core.po.ProductDescription;
import lombok.Data;

/**
Expand All @@ -25,34 +24,17 @@ public class ProductVo {
* 这变量储存商品第一张图片的地址
*/
private String firstImageUrl;

/**
* 商品详情
* 分类名称
*/
private ProductDescription productDescription;
private String categoryName;

public ProductVo(Product product){
public ProductVo(Product product) {
this.product = product;
//获取商品图片url数组
imagesUrls = product.getImageUrls().split(Product.IMAGE_SEPARATION);
firstImageUrl = imagesUrls[0];
}


/**
* 分类名称
*/
private String categoryName;
private String description;

// /**
// * 此变量储存商品详情图片的url
// */
// private String[] descriptionImagesUrls;
//
// /**
// * 配置信息
// */
// private Map<String, String> params = new HashMap<String, String>();

}

This file was deleted.

60 changes: 53 additions & 7 deletions mall-dao-impl/src/main/resources/mapper/ProductMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<select id="findAll" resultType="Product">
SELECT *
FROM `product`
${page.queryString}
${page.queryString}
</select>

<select id="findByCategoryIdIn" resultType="Product">
Expand All @@ -30,11 +30,57 @@
${page.queryString}
</select>

<!--查找商品详情-->
<select id="findDescriptionById" resultType="ProductDescription" parameterType="Long">
SELECT *
FROM `product_description`
WHERE product_id = #{productId}
</select>
<insert id="add" parameterType="Product" useGeneratedKeys="true" keyProperty="id">
INSERT INTO `product`
(name, price, discount, status, category_id, store_num, sale_num, image_urls, comment_num, sale_date, description)
VALUES (
#{name}, #{price}, #{discount}, #{status}, #{categoryId}, #{storeNum}, #{saleNum}, #{imageUrls},
#{commentNum}, #{saleDate}, #{description}
)
</insert>

<delete id="deleteById" parameterType="Long">
DELETE FROM `product`
WHERE id = #{id}
</delete>

<update id="updateSelectionById" parameterType="Product">
UPDATE `product`
<set>
<if test="name!=null">
name = #{name}
</if>
<if test="price!=null">
price = #{price}
</if>
<if test="discount!=null">
discount = #{discount}
</if>
<if test="status!=null">
status = #{status}
</if>
<if test="category_id!=null">
category_id = #{categoryId}
</if>
<if test="storeNum!=null">
store_num = #{storeNum}
</if>
<if test="saleNum!=null">
sale_num = #{saleNum}
</if>
<if test="imageUrls!=null">
image_urls = #{imageUrls}
</if>
<if test="commentNum!=null">
comment_num = #{commentNum}
</if>
<if test="saleDate!=null">
sale_date = #{saleDate}
</if>
<if test="description!=null">
description = #{description}
</if>
</set>
WHERE id = #{id}
</update>
</mapper>
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public interface CartProductDao {
*
* @param cartProductId
*/
void deleteById(Long cartProductId);
int deleteById(Long cartProductId);

/**
* 更新购物车中不为null的字段
Expand Down
22 changes: 18 additions & 4 deletions mall-dao/src/main/java/com/rhinoceros/mall/dao/dao/ProductDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
/* created at 3:37 PM 2/28/2018 */

import com.rhinoceros.mall.core.po.Product;
import com.rhinoceros.mall.core.po.ProductDescription;
import com.rhinoceros.mall.core.query.PageQuery;
import org.apache.ibatis.annotations.Param;

Expand Down Expand Up @@ -36,12 +35,27 @@ public interface ProductDao {
*/
List<Product> findByCategoryIdIn(@Param("categoryIds") List<Long> categoryIds, @Param("page") PageQuery pageQuery);

/**
* 添加商品
*
* @param product
* @return
*/
int add(Product product);

/**
* 根据id删除商品
*
* @param id
* @return
*/
int deleteById(Long id);

/**
* 根据产品id查找产品详情
* 根据id更新所有不为null的字段
*
* @param productId
* @param product
* @return
*/
ProductDescription findDescriptionById(Long productId);
int updateSelectionById(Product product);
}
20 changes: 16 additions & 4 deletions mall-manager-impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>mall-manager-impl</artifactId>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
Expand All @@ -25,10 +37,10 @@
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<!--<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-elasticsearch</artifactId>
</dependency>-->
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
</dependency>
</dependencies>

</project>
Loading

0 comments on commit bbed92b

Please sign in to comment.