前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >商品管理系统_营销系统四大系统

商品管理系统_营销系统四大系统

作者头像
全栈程序员站长
发布2022-09-20 10:26:07
5570
发布2022-09-20 10:26:07
举报
文章被收录于专栏:全栈程序员必看

题目: 商品管理系统

  • 语言和环境
  1. 实现语言

Java

  1. 环境要求

JDK8, IDEA, Tomcat7, MySQL

  • 功能要求

项目开发使用SSM(Mybatis + Spring + Springmvc)实现商品管理相关功能,MySQL作为后台数据库。功能包括查询商品列表,添加商品信息等,具体要求如下:

  1. 系统首页, 显示页面如图-1:
商品管理系统_营销系统四大系统
商品管理系统_营销系统四大系统

图-1

  1. 点击”添加商品”按钮, 进入商品添加页面. 添加商品时要求商品类型动态从商品类型表获取, 同时实现商品图片的上传功能, 添加成功后进入商品列表页面. 如图-2:
商品管理系统_营销系统四大系统
商品管理系统_营销系统四大系统

图-2

  1. 商品列表页面要支持条件查询,商品类型要求加载商品类型表中的数据动态生成, 商品名称支持模糊查询, 如图-3:
商品管理系统_营销系统四大系统
商品管理系统_营销系统四大系统

图-3

  1. 点击”详情”按钮时, 要求使用ajax异步加载当前商品的图片和描述信息, 追加在当前行下. 要求点击详情时交换显示隐藏图片和描述信息. 如图-4:
商品管理系统_营销系统四大系统
商品管理系统_营销系统四大系统

图-4

  • 数据库设计

数据库表名称及要求:

表名

tb_goods_type

中文表名称

商品类型表

主键

typeid

序号

字段名称

字段说明

类型

长度

属性

备注

1

typeid

类型编号

Integer

主键

自增

2

typename

类型名称

VARCHAR(20)

20

非空

表名

tb_goods

中文表名称

商品表

主键

goodsid

序号

字段名称

字段说明

类型

长度

属性

备注

1

goodsid

商品编号

Integer

主键

自增

2

name

商品名称

varchar(50)

50

非空

3

brand

品牌

varchar(50)

50

非空

4

model

型号

varchar(50)

50

非空

5

price

单价

double(10,2)

10,2

非空

6

picture

图片

varchar(255)

255

非空

7

description

商品描述

text

8

typeid

类型编号

Integer

外键, 参照商品类型表

  • 注意事项
  1. 请注意界面美观, 控件摆放整齐;
  2. 请注意代码的书写, 命名符合规范, 在代码中添加必要的注释;
  3. 请注意操作数据库时进行必要的异常处理;
  4. 使用MVC模式进行开发, 包括视图层, 控制层, 业务层和数据访问层. 省略某层, 扣除该层分数;
  5. 将数据库导出成SQL文件, 其中包括创建表结构, 创建主外键, 与项目代码一起提交.

项目总览(dubbo)

商品管理系统_营销系统四大系统
商品管理系统_营销系统四大系统

pom.xml(WorkParent)

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.bisxt</groupId>
  <artifactId>WorkParent</artifactId>
  <version>1.0-SNAPSHOT</version>
  <modules>
    <module>../Provider_goods</module>
    <module>../Service_goods_web</module>
  </modules>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
    </dependency>
  </dependencies>
  <packaging>pom</packaging>
  <name>WorkParent</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
    <junit.version>4.12</junit.version>
    <spring.version>4.3.18.RELEASE</spring.version>
    <mybatis.version>3.2.8</mybatis.version>
    <mybatis.spring.version>1.2.2</mybatis.spring.version>
    <mybatis.paginator.version>1.2.15</mybatis.paginator.version>
    <mysql.version>5.1.32</mysql.version>
    <slf4j.version>1.6.4</slf4j.version>
    <jackson.version>2.8.2</jackson.version>
    <druid.version>1.0.9</druid.version>
    <jstl.version>1.2</jstl.version>
    <servlet-api.version>2.5</servlet-api.version>
    <jsp-api.version>2.0</jsp-api.version>
    <joda-time.version>2.5</joda-time.version>
    <commons-lang3.version>3.3.2</commons-lang3.version>
    <commons-io.version>1.3.2</commons-io.version>
    <!-- ftpk客户端  -->
    <commons-net.version>3.3</commons-net.version>
    <pagehelper.version>4.0.3</pagehelper.version>
    <jsqlparser.version>0.9.1</jsqlparser.version>
    <commons-fileupload.version>1.3.1</commons-fileupload.version>
    <jedis.version>2.9.0</jedis.version>
    <solrj.version>4.10.3</solrj.version>
    <dubbo.version>2.5.3</dubbo.version>
    <zkclient.version>0.10</zkclient.version>
    <httpcomponents.version>4.4.1</httpcomponents.version>
    <noggit.version>0.6</noggit.version>
    <zookeeper.version>3.4.6</zookeeper.version>
    <log4j.version>1.2.17</log4j.version>
    <aspectj.version>1.8.2</aspectj.version>
    <aopalliance.version>1.0</aopalliance.version>
    <spring.data.redis.version>1.7.11.RELEASE</spring.data.redis.version>


    <tomcat.version>2.2</tomcat.version>
  </properties>



  <dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.springframework.data</groupId>
      <artifactId>spring-data-redis</artifactId>
      <version>${spring.data.redis.version}</version>
      <exclusions>
        <exclusion>
          <groupId>org.springframework</groupId>
          <artifactId>spring-context</artifactId>
        </exclusion>
        <exclusion>
          <groupId>org.springframework</groupId>
          <artifactId>spring-context-support</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>aopalliance</groupId>
      <artifactId>aopalliance</artifactId>
      <version>${aopalliance.version}</version>
    </dependency>

    <dependency>
      <groupId>org.aspectj</groupId>
      <artifactId>aspectjweaver</artifactId>
      <version>${aspectj.version}</version>
    </dependency>

    <dependency>
      <groupId>org.apache.zookeeper</groupId>
      <artifactId>zookeeper</artifactId>
      <version>${zookeeper.version}</version>
    </dependency>
    <!-- 时间操作组件 -->
    <dependency>
      <groupId>joda-time</groupId>
      <artifactId>joda-time</artifactId>
      <version>${joda-time.version}</version>
    </dependency>
    <!-- Apache工具组件 -->
    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-lang3</artifactId>
      <version>${commons-lang3.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-io</artifactId>
      <version>${commons-io.version}</version>
    </dependency>
    <dependency>
      <groupId>commons-net</groupId>
      <artifactId>commons-net</artifactId>
      <version>${commons-net.version}</version>
    </dependency>
    <!-- Jackson Json处理工具包 -->
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
      <version>${jackson.version}</version>
    </dependency>
    <dependency>
      <groupId>com.alibaba</groupId>
      <artifactId>dubbo</artifactId>
      <exclusions>
        <!-- 排除或者不适用dubbo中指定的spring版本 -->
        <exclusion>
          <groupId>org.springframework</groupId>
          <artifactId>spring</artifactId>
        </exclusion>
      </exclusions>
      <version>${dubbo.version}</version>
    </dependency>
    <!-- 单元测试 -->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>${junit.version}</version>
      <scope>test</scope>
    </dependency>
    <!-- 日志处理 -->
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-log4j12</artifactId>
      <version>${slf4j.version}</version>
    </dependency>
    <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>${log4j.version}</version>
    </dependency>

    <!-- Mybatis -->
    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis</artifactId>
      <version>${mybatis.version}</version>
    </dependency>
    <dependency>
      <groupId>commons-fileupload</groupId>
      <artifactId>commons-fileupload</artifactId>
      <version>${commons-fileupload.version}</version>
    </dependency>

    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis-spring</artifactId>
      <version>${mybatis.spring.version}</version>
    </dependency>
    <!-- mybatis的分页插件 -->
    <dependency>
      <groupId>com.github.miemiedev</groupId>
      <artifactId>mybatis-paginator</artifactId>
      <version>${mybatis.paginator.version}</version>
    </dependency>
    <dependency>
      <groupId>com.github.pagehelper</groupId>
      <artifactId>pagehelper</artifactId>
      <version>${pagehelper.version}</version>
    </dependency>
    <!-- MySql -->
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>${mysql.version}</version>
    </dependency>
    <!-- 连接池 -->
    <dependency>
      <groupId>com.alibaba</groupId>
      <artifactId>druid</artifactId>
      <version>${druid.version}</version>
    </dependency>
    <!-- Spring -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>${spring.version}</version>
    </dependency>

    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context-support</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-beans</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>${spring.version}</version>
    </dependency>

    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-jdbc</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-tx</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-aop</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-aspects</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <!-- JSP相关 -->
    <dependency>
      <groupId>jstl</groupId>
      <artifactId>jstl</artifactId>
      <version>${jstl.version}</version>
    </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>servlet-api</artifactId>
      <version>${servlet-api.version}</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>jsp-api</artifactId>
      <version>${jsp-api.version}</version>
      <scope>provided</scope>
    </dependency>
    <!-- Redis客户端 -->
    <dependency>
      <groupId>redis.clients</groupId>
      <artifactId>jedis</artifactId>
      <version>${jedis.version}</version>
    </dependency>
    <!-- solr客户端 -->
    <dependency>
      <groupId>org.apache.solr</groupId>
      <artifactId>solr-solrj</artifactId>
      <version>${solrj.version}</version>
    </dependency>
    <!-- zookeeper客户端 -->
    <dependency>
      <groupId>com.101tec</groupId>
      <artifactId>zkclient</artifactId>
      <version>${zkclient.version}</version>
    </dependency>
    <dependency>
      <groupId>org.noggit</groupId>
      <artifactId>noggit</artifactId>
      <version>${noggit.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.httpcomponents</groupId>
      <artifactId>httpclient</artifactId>
      <version>${httpcomponents.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.httpcomponents</groupId>
      <artifactId>httpmime</artifactId>
      <version>${httpcomponents.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.httpcomponents</groupId>
      <artifactId>httpcore</artifactId>
      <version>${httpcomponents.version}</version>
    </dependency>
  </dependencies>
  </dependencyManagement>
  <build>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-jar-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
        <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
        <plugin>
          <artifactId>maven-site-plugin</artifactId>
          <version>3.7.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-project-info-reports-plugin</artifactId>
          <version>3.0.0</version>
        </plugin>



        <!-- 配置Tomcat插件 -->
        <plugin>
          <groupId>org.apache.tomcat.maven</groupId>
          <artifactId>tomcat7-maven-plugin</artifactId>
          <version>${tomcat.version}</version>
        </plugin>
      </plugins>
    </pluginManagement>

    <resources>
    <resource>
      <directory>src/main/java</directory>
      <includes>
        <include>**/*.xml</include>
      </includes>
    </resource>
    <resource>
      <directory>src/main/resources</directory>
      <includes>
        <include>**/*.xml</include>
        <include>**/*.properties</include>
      </includes>
    </resource>

    </resources>
  </build>
</project>

mapper和pojo都是逆向生成的(mybatis逆向生成配置文件

com.bisxt.goods.service.GoodsService

代码语言:javascript
复制
package com.bisxt.goods.service;

import com.bisxt.goods.pojo.TbGoods;

import java.util.List;

public interface GoodsService {
    /**
     * 查询所有商品
     * @return
     */
    public List<TbGoods>  selGoods();

    /**
     * 添加s商品
     * @param tbGoods
     * @return
     */
    public int  saveGoods(TbGoods tbGoods);

    /**
     * 根据cid查询商品
     * @param cid
     * @return
     */
    public TbGoods selByCidService(Integer cid);


    public List<TbGoods>  selAllLikeGoods(String name);
}

com.bisxt.goods.service.impl.GoodsServiceImpl

代码语言:javascript
复制
package com.bisxt.goods.service.impl;

import com.bisxt.goods.mapper.TbGoodsMapper;
import com.bisxt.goods.pojo.TbGoods;
import com.bisxt.goods.pojo.TbGoodsExample;
import com.bisxt.goods.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class GoodsServiceImpl implements GoodsService {
    @Autowired
    private TbGoodsMapper tbGoodsMapper;
    @Override
    public List<TbGoods> selGoods() {
        TbGoodsExample example=new TbGoodsExample();

        List<TbGoods> tbGoods = this.tbGoodsMapper.selectByExample(example);
        return tbGoods;
    }

    @Override
    public int saveGoods(TbGoods tbGoods) {
        return  this.tbGoodsMapper.insert(tbGoods);

    }

    @Override
    public TbGoods selByCidService(Integer cid) {
      return   this.tbGoodsMapper.selectByPrimaryKey(cid);

    }

    @Override
    public List<TbGoods> selAllLikeGoods(String name) {
        TbGoodsExample example=new TbGoodsExample();
        TbGoodsExample.Criteria criteria = example.createCriteria();
        if(name!=null &&!"".equals(name)){
            criteria.andNameLike("%"+name+"%");
        }

      return   this.tbGoodsMapper.selectByExample(example);

    }
}

俩个工具类

商品管理系统_营销系统四大系统
商品管理系统_营销系统四大系统

com.bisxt.beans.FtpUtil

代码语言:javascript
复制
package com.bisxt.beans;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPReply;

/**
 * ftp上传下载工具类
 */
public class FtpUtil {

	/** 
	 * Description: 向FTP服务器上传文件 
	 * @param host FTP服务器hostname 
	 * @param port FTP服务器端口 
	 * @param username FTP登录账号 
	 * @param password FTP登录密码 
	 * @param basePath FTP服务器基础目录
	 * @param filePath FTP服务器文件存放路径。例如分日期存放:/2015/01/01。文件的路径为basePath+filePath
	 * @param filename 上传到FTP服务器上的文件名 
	 * @param input 输入流 
	 * @return 成功返回true,否则返回false 
	 */  
public static boolean uploadFile(String host, int port, String username, String password, String basePath,
			String filePath, String filename, InputStream input) {
		boolean result = false;
		FTPClient ftp = new FTPClient();
		try {
			int reply;
			ftp.connect(host, port);// 连接FTP服务器
			// 如果采用默认端口,可以使用ftp.connect(host)的方式直接连接FTP服务器
			ftp.login(username, password);// 登录
			reply = ftp.getReplyCode();
			if (!FTPReply.isPositiveCompletion(reply)) {
				ftp.disconnect();
				return result;
			}
			//切换到上传目录
			if (!ftp.changeWorkingDirectory(basePath+filePath)) {
				//如果目录不存在创建目录
				String[] dirs = filePath.split("/");
				String tempPath = basePath;
				for (String dir : dirs) {
					if (null == dir || "".equals(dir)) continue;
					tempPath += "/" + dir;
					if (!ftp.changeWorkingDirectory(tempPath)) {
						if (!ftp.makeDirectory(tempPath)) {
							return result;
						} else {
							ftp.changeWorkingDirectory(tempPath);
						}
					}
				}
			}
			//设置上传文件的类型为二进制类型
			ftp.setFileType(FTP.BINARY_FILE_TYPE);
			//上传文件
			if (!ftp.storeFile(filename, input)) {
				return result;
			}
			input.close();
			ftp.logout();
			result = true;
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (ftp.isConnected()) {
				try {
					ftp.disconnect();
				} catch (IOException ioe) {
				}
			}
		}
		return result;
	}
	
	/** 
	 * Description: 从FTP服务器下载文件 
	 * @param host FTP服务器hostname 
	 * @param port FTP服务器端口 
	 * @param username FTP登录账号 
	 * @param password FTP登录密码 
	 * @param remotePath FTP服务器上的相对路径 
	 * @param fileName 要下载的文件名 
	 * @param localPath 下载后保存到本地的路径 
	 * @return 
	 */  
	public static boolean downloadFile(String host, int port, String username, String password, String remotePath,
			String fileName, String localPath) {
		boolean result = false;
		FTPClient ftp = new FTPClient();
		try {
			int reply;
			ftp.connect(host, port);
			// 如果采用默认端口,可以使用ftp.connect(host)的方式直接连接FTP服务器
			ftp.login(username, password);// 登录
			reply = ftp.getReplyCode();
			if (!FTPReply.isPositiveCompletion(reply)) {
				ftp.disconnect();
				return result;
			}
			ftp.changeWorkingDirectory(remotePath);// 转移到FTP服务器目录
			FTPFile[] fs = ftp.listFiles();
			for (FTPFile ff : fs) {
				if (ff.getName().equals(fileName)) {
					File localFile = new File(localPath + "/" + ff.getName());

					OutputStream is = new FileOutputStream(localFile);
					ftp.retrieveFile(ff.getName(), is);
					is.close();
				}
			}

			ftp.logout();
			result = true;
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (ftp.isConnected()) {
				try {
					ftp.disconnect();
				} catch (IOException ioe) {
				}
			}
		}
		return result;
	}
	
	public static void main(String[] args) {
		try {  
	        FileInputStream in=new FileInputStream(new File("D:\\1.jpg"));  
	        boolean flag = uploadFile("192.168.10.128", 21, "ftpuser", "ftpuser", "/home/ftpuser/www/images","/2015/01/21", "gaigeming.jpg", in);  
	        System.out.println(flag);  
	    } catch (FileNotFoundException e) {  
	        e.printStackTrace();  
	    }  
	}
}

com.bisxt.beans.IDUtils

代码语言:javascript
复制
package com.bisxt.beans;

import java.util.Random;
import java.util.UUID;

/**
 * 各种id生成策略
 * @version 1.0
 */
public class IDUtils {

	/**
	 * 图片名生成
	 */
	public static String genImageName() {
		//取当前时间的长整形值包含毫秒
		long millis = System.currentTimeMillis();
		//long millis = System.nanoTime();
		//加上三位随机数
		Random random = new Random();
		int end3 = random.nextInt(1000);
		//如果不足三位前面补0
		String str = millis + String.format("%03d", end3);
		return str;
	}
	
	/**
	 * 商品id生成
	 */
	public static long genItemId() {
		//取当前时间的长整形值包含毫秒
		long millis = System.currentTimeMillis();
		//long millis = System.nanoTime();
		//加上两位随机数
		Random random = new Random();
		int end2 = random.nextInt(99);
		//如果不足两位前面补0
		String str = millis + String.format("%02d", end2);
		long id = new Long(str);
		return id;
	}
	
	public static void main(String[] args) {
		for(int i=0;i< 100;i++)
		System.out.println(genItemId());
	}
}

com.bisxt.goods.service.ServiceGoodsService

代码语言:javascript
复制
package com.bisxt.goods.service;

import com.bisxt.goods.pojo.TbGoods;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

public interface ServiceGoodsService {
    /**
     * 查询所有商品
     * @return
     */
    public List<TbGoods>  selAllGooods();

    /**
     * 新增商品
     * @param tbGoods
     * @return
     */
    public int saveGoodsService(TbGoods tbGoods, MultipartFile file);

    /**
     * 根据cid 查询商品
     * @param cid
     * @return
     */
    public TbGoods selByCidService(Integer cid);

    /**
     * 模糊查询
     * @param name
     * @return
     */
    public  List<TbGoods> selAllgoodsService(String name);
}

com.bisxt.goods.service.impl.ServiceGoodsServiceImpl

代码语言:javascript
复制
package com.bisxt.goods.service.impl;

import com.bisxt.beans.FtpUtil;
import com.bisxt.beans.IDUtils;
import com.bisxt.goods.pojo.TbGoods;
import com.bisxt.goods.service.GoodsService;
import com.bisxt.goods.service.ServiceGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
@Service
public class ServiceGoodsServiceImpl implements ServiceGoodsService {
    @Value("${FTP_HOST}")
    private String FTP_HOST;
    @Value("${FTP_PORT}")
    private Integer FTP_PORT;
    @Value("${FTP_USERNAME}")
    private String FTP_USERNAME;
    @Value("${FTP_PASSWORD}")
    private String FTP_PASSWORD;
    @Value("${FTP_PATH}")
    private String FTP_PATH;
    @Value("${IMAGE_HTTP_PATH}")
    private String IMAGE_HTTP_PATH;
    @Autowired
    private GoodsService goodsServiceProxy;
    @Override
    public List<TbGoods> selAllGooods() {
        List<TbGoods> tbGoods = this.goodsServiceProxy.selGoods();
        return tbGoods;
    }

    @Override
    public int saveGoodsService(TbGoods tbGoods, MultipartFile file) {
        String fileName=null;
        boolean flag=false;
        int n=0;
        try {
            String originalFilename = file.getOriginalFilename();
            System.out.println("hhhhhh"+originalFilename);


            String etc=originalFilename.substring(originalFilename.lastIndexOf("."));
            fileName = IDUtils.genImageName()+etc;

            InputStream local = file.getInputStream();
            Date date=new Date();
            SimpleDateFormat sf=new SimpleDateFormat("/yyyy.MM.dd/");

            String path=sf.format(date);
            flag=FtpUtil.uploadFile(FTP_HOST,FTP_PORT, FTP_USERNAME, FTP_PASSWORD, FTP_PATH,path ,fileName,local);
            tbGoods.setPicture(IMAGE_HTTP_PATH+path+fileName);
            n = this.goodsServiceProxy.saveGoods(tbGoods);

        }catch (Exception e){
            e.printStackTrace();
        }
        return n;
    }

    @Override
    public TbGoods selByCidService(Integer cid) {
        return this.goodsServiceProxy.selByCidService(cid);
    }

    @Override
    public List<TbGoods> selAllgoodsService(String name) {
        return this.goodsServiceProxy.selAllLikeGoods(name);
    }
}

com.bisxt.goods.controller.GoodsController

代码语言:javascript
复制
package com.bisxt.goods.controller;

import com.bisxt.goods.pojo.TbGoodType;
import com.bisxt.goods.pojo.TbGoods;
import com.bisxt.goods.service.AllGoodstypeService;
import com.bisxt.goods.service.ServiceGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Controller
public class GoodsController {
    @Autowired
    private ServiceGoodsService serviceGoodsService;
    @Autowired
    private AllGoodstypeService allGoodstypeService;
    @RequestMapping("/goods/select")
    public String selGoodsController(Model model){
        List<TbGoods> tbGoods = this.serviceGoodsService.selAllGooods();
        model.addAttribute("list", tbGoods);
        List<TbGoodType> tbGoodTypes = this.allGoodstypeService.selAlltypes();
        model.addAttribute("tbGoodTypes",tbGoodTypes);
         return "welcome";
    }


    @RequestMapping("/goods/insert")
    public String selGoodsController(TbGoods tbGoods, MultipartFile file){
        int i = this.serviceGoodsService.saveGoodsService(tbGoods, file);
        if(i>0){
            return "forword:/goods/select" ;
        }
        return "addUser";
    }

    @RequestMapping("/goods/ajax")
    @ResponseBody
    public TbGoods selByCidGoodsController(Integer cid){
        return  this.serviceGoodsService.selByCidService(cid);
    }

    @RequestMapping("/goods/like")
    public String selByLike(String name,Model model){

        List<TbGoods> tbGoods = this.serviceGoodsService.selAllgoodsService(name);

        model.addAttribute("list", tbGoods);
        return "welcome";
    }

}

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/168403.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
数据库
云数据库为企业提供了完善的关系型数据库、非关系型数据库、分析型数据库和数据库生态工具。您可以通过产品选择和组合搭建,轻松实现高可靠、高可用性、高性能等数据库需求。云数据库服务也可大幅减少您的运维工作量,更专注于业务发展,让企业一站式享受数据上云及分布式架构的技术红利!
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档