SSM上传图片视频到本地和云服务器完整项目(含jsp及controller)

先上需求




接下来是数据库的设计:理想的应该是设计三个表,分为样式表(素材中列出的元素要求)、素材id表(自身主键ID     filePathID的外键是路径表的ID   fileId的外键是样式表的ID)、素材路径表(主键ID   素材路径Path)

目前因为时间原因,只是两个表,样式表和 素材表(主键ID 素材路径filepah  fileId的外键是样式表的ID)





接下来就是代码了,整个项目的做法是:

①先根据上传的文件MultipartFile []file获得要上传的文件数量number,由number获得photoFlag,再由这两个元素获得样式ID,从而获得整个样式的所有属性。(其实直接遍历每个样式信息存到list也可以,但是我觉得这样子逐个获得信息,在接下来的判断比较中效率应该高点,条理清晰点)

②判断上传的文件是否符合样式,就是先比较number是否相等,photoFlag是否相等,ID对应的其它属性是否相等。

③如果相等就上传到本地,这里新建一个文件夹存放文件(E://a)上传到本地,然后通过本地文件的已知路径再上传到云,然后再把路径信息插入数据库。

另外项目有一个很大的不足之处,是我一定要先上传到本地新建的文件夹中,才能上传到云。因为上传到云需要文件的路径,但是MultipartFile []file获取不到路径。当然如果是在兼容模式下可以直接通过

document.getElementById(id)

在选择文件上传的jsp中直接获得value,其路径值。否则在非兼容模式只会获得fakePath。

这涉及到一些相对路径、绝对路径的问题,我这方面暂时还不太了解。


接下来直接上代码,SSM的框架搭建方式在此就不上传,只提供解决需求的项目思路及其代码:

springmvc.xml-->upload.jsp-->controller-->cloudFile.jsp


springmvc.xml中要记得添加文件上传解析器

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">

	<!-- 全扫描
	<context:component-scan base-package="com.fxy"></context:component-scan>
	 -->
	<!-- 只扫描指定的Controller层和Service层 -->
	<context:component-scan base-package="com.fxy"
		use-default-filters="false">
		<!-- 不扫描哪层 
		<context:exclude-filter type="annotation" expression=""/>
			   扫描哪层-->
		<context:include-filter type="annotation"
			expression="org.springframework.stereotype.Controller" />
		<context:include-filter type="annotation"
			expression="org.springframework.stereotype.Service" />
	</context:component-scan>

	<!-- 定义文件上传解析器 -->  
    <bean id="multipartResolver"  
        class="org.springframework.web.multipart.commons.CommonsMultipartResolver">  
        <!-- 设定默认编码 -->  
        <property name="defaultEncoding" value="UTF-8"></property>  
        <!-- 设定文件上传的最大值5MB,5*1024*1024 -->  
        <property name="maxUploadSize" value="99999999"></property>  
    </bean>  



	<!-- 赋值前缀,后缀 -->
	<bean
		class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		 <property name="prefix" value="/"></property> 
		<property name="suffix" value=".jsp"></property>
	</bean>
	
	<!-- 两个标准配置 -->
	<!-- 将SpringMVC不能处理的请求交给tomcat -->
	<mvc:default-servlet-handler />
	<!-- 支持SpringMVC更高级的一些功能,JSR303校验,快捷ajax请求 -->
	<mvc:annotation-driven />
	
	

</beans>


upload.jsp中主要就是多文件上传需要添加enctype="multipart/form-data"  和 multiple  

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>upload选择上传的文件</title>
<script type="text/javascript"
	src="static/js/common/jquery-1.12.4.min.js"></script>

</head>
<body>
<h1>${err }</h1>
	<form id="uploadForm" enctype="multipart/form-data" action="loadPath" method="post">
		<input id="file" type="file" name="file" multiple/>
		<input type="submit" value="submit">
		<!-- <button id="upload" type="button" οnclick="clickbtnGet();">upload</button> -->
	</form>

</body>
</html>



Controller中主要就是不要加上注解@ResquestBody  加了这个注解,return "字符串" 就会跳转不到jsp,而是直接输出该字符串。


import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.fileupload.disk.DiskFileItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.commons.CommonsMultipartFile;


import it.sauronsoftware.jave.Encoder;
import it.sauronsoftware.jave.EncoderException;
import it.sauronsoftware.jave.InputFormatException;
import it.sauronsoftware.jave.MultimediaInfo;
import main.java.com.UpYun;

@Controller
public class localUploadController {

	@Autowired
	queryStyleService qStyleService;

	@Autowired
	sourceService sService;

	
	@RequestMapping(value = "loadPath", method = RequestMethod.POST)
	public String loadPath(HttpServletRequest request,@RequestParam("file")MultipartFile []file) {
		
		// 获得上传的文件个数
		int num = file.length;
		System.out.println("上传的文件个数:"+num);
		// 查Style表样式的对应数量number
		List<Style> numberStyle = qStyleService.queryNumber();
		int number = 0;
		int flag = -2;
		for (Style style : numberStyle) {
			number = style.getNumber();
			// begin:上传的文件数量跟某个样式之一的文件个数相等,可能是样式之一
			if (number == num) {
				// 判断数据库中相应文件个数是否支持扩展
				List<Style> flagStyle = qStyleService.selectByNumber(number);

				// 遍历flag的值
				for (Style style2 : flagStyle) {
					flag = style2.getPhotoflag();
					System.out.println("flag的值:"+flag);
					int jpgCount = 0;
					// 遍历文件数组获得后缀
					for (MultipartFile multipartFile : file) {
						String nm = multipartFile.getOriginalFilename();
						String Suffix = nm.substring(nm.length() - 3);
						System.out.println("nm文件名:"+nm);
						if ("jpg".equals(Suffix)) {
							jpgCount++;
						}
						if (jpgCount == number) {
							boolean state = styleFive(request, flag, number, file);
							if (state) {
								return "cloudFile";
								} else {
									System.out.println("86不不不不符合样式");
									//return "wrong";
								}
							} else {
								boolean state = styleFive(request, flag, number, file);
								if (state) {
									return "cloudFile";
								} else {
									System.out.println("94不不不不符合样式");
									//return "wrong";
								}
							}

						}

					} // end:for (Style style2 : flagStyle)
						// end:可能是样式之一:上传的文件数量跟某个样式之一的文件个数相等

				}
				// begin:不符合样式:上传的文件数量跟某个样式之一的文件个数不相等
				// number != num
				else {

				}
				// end:不符合样式:上传的文件数量跟某个样式之一的文件个数不相等

			} // end:for (Style style : numberStyle)
			System.out.println("113");
			request.getSession().setAttribute("err", "上传的文件不符合格式");
			return "upload";

	}

	/**
	 * @function styleFive
	 * @param localFilePath
	 * @param flag
	 * @param number
	 * @param strs
	 * @return state
	 */
	public boolean styleFive(HttpServletRequest request, int flag, int number, MultipartFile []file) {
		boolean state = false;

		float length = 0;
		int width = 0;
		int height = 0;
		// 判断符合格式的文件个数
		int count = 0;
		// 遍历文件数组获得后缀
		for (MultipartFile multipartFile : file) {
			String nm = multipartFile.getOriginalFilename();
			String Suffix = nm.substring(nm.lastIndexOf("."));
			System.out.println("nm文件名:"+nm);
			System.out.println("后缀:"+Suffix);
			// 对比jpg的文件格式对不对
			if (".jpg".equals(Suffix)) {
				length = multipartFile.getSize()/1024;
				System.out.println("每一个Jpg文件的大小:"+length);
				
				InputStream inputStream = null;
				try {
					inputStream = multipartFile.getInputStream();
					BufferedImage image = ImageIO.read(inputStream);
					height = image.getHeight();
					width = image.getWidth();
					System.err.println("图片width:"+width);
					System.err.println("图片height:"+height);
					
					// 获得number、flag对应的样式的id
					List<Style> idStyles = qStyleService.selectByNumFlag(number, flag);
					for (Style style : idStyles) {
						int idTurn = style.getId();
						System.out.println("idTurn:"+idTurn);
						// 根据idStyle获得该样式的数据
						Style StyleSource = qStyleService.queryById(idTurn);
						
						//TODO:第3个样式没有成功
						
						// begin:对比判断符不符合样式
						if (StyleSource.getPhotoflag() == 0) {
							// 不支持扩展
							if ((StyleSource.getPhotowidth() == width) && (StyleSource.getPhotoheight() == height)
									&& (length < StyleSource.getPhotolarge() || length == StyleSource.getPhotolarge())) {
								count++;
								System.out.println("这个文件符合格式jpg:");
							} else {
								System.out.println("不符合样式格式");
								System.out.println("是战力嘛???");
								//return state;
							}
						} else if (StyleSource.getPhotoflag() == 1) {
							// 支持扩展
							if ((StyleSource.getPhotowidth() % width == 0 || width % StyleSource.getPhotowidth() == 0)
									&& (StyleSource.getPhotoheight() % height == 0
											|| height % StyleSource.getPhotoheight() == 0)
									&& (length < StyleSource.getPhotolarge() || length == StyleSource.getPhotolarge())) {
								count++;
								System.out.println("这个文件符合格式jpg:");
							} else {
								System.out.println("不符合样式");
								//return state;
							}
						}
						// flag==-1 没有图片,就不判断

					}
					
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}finally {
					if (inputStream != null) {  
			               try {  
			                   inputStream.close(); // 关闭流  
			               } catch (IOException e) {  
			                   System.out.println("guandiaolelelellelelele");
			               }  
			           }  
				}
				
				

				// end:对比判断符不符合样式
				// 对比判断mp4文件符不符合格式
			} else if (".mp4".equals(Suffix)) {
				float videoLarge = 0;
				int videoWidth = 0;
				int videoHeight = 0;
				CommonsMultipartFile cf = (CommonsMultipartFile)multipartFile;  
		        DiskFileItem fi = (DiskFileItem) cf.getFileItem();  
		        File vedioFile = fi.getStoreLocation(); 
				Encoder encoder = new Encoder();
				MultimediaInfo info;
				try {
					info = encoder.getInfo(vedioFile);
				
				videoHeight = info.getVideo().getSize().getHeight();
				videoWidth  = info.getVideo().getSize().getWidth();
				
				videoLarge = multipartFile.getSize()/1024;
				
				System.out.println("videoHeight:"+videoHeight);
				System.out.println("videoWidth:"+videoWidth);
				System.out.println("videoLarge:"+videoLarge);
				// end:获得上传文件的尺寸信息
				System.out.println("得到上传的可能符合样式的信息");
				// begin:对比判断符不符合样式

				// 获得number、flag对应的样式的id
				List<Style> idStyles = qStyleService.selectByNumFlag(number, flag);
				for (Style style : idStyles) {
					// 根据idStyle获得该样式的数据
					Style StyleSource = qStyleService.queryById(style.getId());

					if ((StyleSource.getVideowidth() == videoWidth) && (StyleSource.getVideoheight() == videoHeight)
							&& (videoLarge < StyleSource.getVideolarge()
									|| videoLarge == StyleSource.getVideolarge())) {
						count++;
					} else {
						System.out.println("不符合样式");
					}
					// end:对比判断符不符合样式5 视频2
				}
				} catch (InputFormatException e) {
					System.out.println("1:");
					e.printStackTrace();
				} catch (EncoderException e) {
					System.out.println("2:");
					e.printStackTrace();
				}
			} else {
				System.out.println("不符合格式");
				return state;
			}
		}
		if (count == number) {
			// 说明上传的文件是样式之一
			state = true;
			
			
			// 上传文件,插入到数据库
			// 已经判断通过属于样式,可以通过number,flag获得样式id
			int id = qStyleService.findIdByNumFlag(number, flag);

			String basePath = "E:\\a";
			String filePath = "";
			String fileName = "";
			List<String> list = new ArrayList<>();
			//上传到本地E盘
			for(MultipartFile file1 : file){  
				fileName = file1.getOriginalFilename();
				System.out.println("fileName:"+fileName);
				filePath = basePath + "/" + fileName;  
			    File desFile = new File(filePath);  
			    if(!desFile.getParentFile().exists()){  
			        desFile.mkdirs();  
			    }  
			    try {  
			        file1.transferTo(desFile);  
			    } catch (IllegalStateException | IOException e) {  
			        e.printStackTrace();  
			    }  
			    
			    list.add(filePath);
			    
			    // 初始化UpYun("空间名称", "操作员名称", "操作员密码")
				UpYun upyun = new UpYun("cloud-video", "***", "***");
				// 采用数据流模式上传文件(节省内存),自动创建父级目录
				boolean result = false;
				String YunPath = "http://cloud-video.test.upcdn.net/";

				// 上传到云
				try {
					result = upyun.writeFile(fileName, desFile, true);
				} catch (IOException e) {
					System.out.println("异常2");
					e.printStackTrace();
				}
				System.out.println("result:"+result);
				String mypath = YunPath + fileName;
				// 把数据插入数据库
				Source source = new Source();
				source.setFilepath(mypath);
				source.setFilestyle(id);
				sService.insertSource(source);
				
				//判断插入的是图片还是视频
				List<String> list1 = new ArrayList<>();
				List<String> list2 = new ArrayList<>();
				for (String string : list) {
					//list1 保存图片
					if ("jpg".equals(string.substring(string.length() - 3))) {
						list1.add(YunPath + string.substring(5,string.length()));
					
					//list2 保存视频
					} else {
						list2.add(YunPath + string.substring(5,string.length()));
					}
				}
				request.getSession().setAttribute("list1", list1);
				System.out.println("request.getSession().getAttribute('list1'):"+request.getSession().getAttribute("list1"));
				request.getSession().setAttribute("list2", list2);
				System.out.println("request.getSession().getAttribute('list2'):"+request.getSession().getAttribute("list2"));
				
				for (String string : list1) {
					System.out.println("list1:"+string);
				}
				for (String string : list2) {
					System.out.println("list2:"+string);
				}
			}  
			
			return state;
		} else {
			return state;
		}
	}

}


cloudFile.jsp中video标签播放视频,如果只有声音没有画面,很大一部分原因都是上传的视频编码是mpeg格式,要转为h264编码才能播放画面。查看视频的这个编码方式,推荐使用potplayer在播放视频姐妹右键属性就可以看到。

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ page isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>成功上传图片视频页面</title>
<script type="text/javascript"
	src="static/js/common/jquery-1.12.4.min.js"></script>
	
</head>
<body >



	<c:forEach items="${list1}" var="result">
		<img alt="" src="${result}">
		
		
	</c:forEach> 

	<c:forEach items="${list2}" var="result2">
	 
	 <video src="${result2}" controls="controls">
您的浏览器不支持 video 标签。
</video>
	 
	 
	 <!-- begin:调用wmp播放器 
	<object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95"
		codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,1,5,217"
		id="MediaPlayer" type=application/x-oleobject width="560" height="360"
		standby="Loading Microsoft Windows Media Player components..."
		VIEWASTEXT align="middle">
		<param name="Filename" value=${result2} valuetype="ref">
		<param name="PlayCount" value="0">
		<param name="AutoStart" value="1">
		<param name="ClickToPlay" value="1">
		<param name="EnableFullScreen Controls" value="1">
		<param name="ShowAudio Controls" value="1">
		<param name="EnableContext Menu" value="1">
		<param name="ShowDisplay" value="0">
	</object>
	<!-- end:调用wmp播放器 -->
	 
	</c:forEach> 


</body>
</html>


主要流程就是这样,最后再附上service,dao的方法实现代码。

@Service("queryStyleService")
public class queryStyleServiceImpl implements queryStyleService{

	@Autowired
	StyleMapper styleMapper;
	
	//查询全部Style信息
	@Override
	public List queryStyle() {
		System.out.println("queryStyleServiceImpl.queryStyle()执行了...");
		List list =  (List) styleMapper.queryAll();
		return list;
	}

	//查询单图的尺寸
	@Override
	public List<Style> queryOnePhotoWH(int  count) {
		/*StyleExample example = new StyleExample();
		com.fxy.bean.StyleExample.Criteria criteria = example.createCriteria();
		criteria.andNumberEqualTo(count+1);
		List<Style> list = styleMapper.selectByExample(example);*/
		List<Style> list = styleMapper.selectByCount(count+1);
		System.out.println("list.toString():"+list.toString());
		return list;
	}

	//查Style表样式的对应数量number
	@Override
	public List<Style> queryNumber() {
		List<Style> list = styleMapper.queryNumber();
		System.out.println("list.toString():"+list.toString());
		return list;
	}

	//photoFlag:1 大图    0是小图、组图、视频2    -1 视频1
	@Override
	public List<Style> selectByNumber(int number) {
		//TODO:flag 有三个值,所以不能是int
		List<Style> photoFlag = styleMapper.selectByNumber(number);
		System.out.println("photoFlag:"+photoFlag);
		return photoFlag;
	}

	//获得number、flag对应的样式的id
	@Override
	public List<Style> selectByNumFlag(int number, int flag) {
		List<Style> idStyle = styleMapper.selectByNumFlag(number,flag);
		System.out.println("idStyle:"+idStyle);
		return idStyle;
	}

	//根据idStyle获得该样式的数据
	@Override
	public Style queryById(int idStyle) {
		Style StyleSource = styleMapper.queryById(idStyle);
		System.out.println("StyleSource.toString():"+StyleSource.toString());
		return StyleSource;
	}

	//通过number获得样式id
	@Override
	public int findIdByNum(int number) {
		int id = styleMapper.findIdByNum(number);
		System.out.println("findIdByNum  ID:"+id);
		return id;
	}

	//通过number,flag获得样式id
	@Override
	public int findIdByNumFlag(int number, int flag) {
		int id = styleMapper.findIdByNumFlag(number,flag);
		System.out.println("findIdByNum  ID:"+id);
		return id;
	}

}



@Service("sourceService")
public class sourceServiceImpl implements sourceService{

	@Autowired
	SourceMapper sMapper;
	
	@Override
	public int insertSource(Source source) {
		int flag = sMapper.insertSelective(source);
		System.out.println("flag:"+flag);
		return flag;
	}

}


dao 中

public interface StyleMapper {
	
    int countByExample(StyleExample example);

    int deleteByExample(StyleExample example);

    int deleteByPrimaryKey(Integer id);

    int insert(Style record);

    int insertSelective(Style record);

    List<Style> selectByExample(StyleExample example);

    Style selectByPrimaryKey(Integer id);

    int updateByExampleSelective(@Param("record") Style record, @Param("example") StyleExample example);

    int updateByExample(@Param("record") Style record, @Param("example") StyleExample example);

    int updateByPrimaryKeySelective(Style record);

    int updateByPrimaryKey(Style record);

    //查询全部样式信息
  	List queryAll();
  	
  	//查询上传一个图片的样式信息
  	List<Style> selectByCount(int i);
  	
  	//查Style表样式的对应数量number
  	List<Style> queryNumber();
    
  	//photoFlag:1 大图    0是小图、组图、视频2    -1 视频1
  	List<Style> selectByNumber(int number);

  	//获得number、flag对应的样式的id
  	//两个参数记得@Param("***")
	List<Style> selectByNumFlag(@Param("number")int number,@Param("flag") int flag);

	//根据idStyle获得该样式的数据
	Style queryById(int idStyle);

	
	int findIdByNum(int number);
	
	//通过number,flag获得样式id
	int findIdByNumFlag(@Param("number")int number,@Param("flag") int flag);

    
    
}


实现StyleMapper 的mybatis代码

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.fxy.dao.StyleMapper">
  <resultMap id="BaseResultMap" type="com.fxy.bean.Style">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="describe" jdbcType="VARCHAR" property="describe" />
    <result column="number" jdbcType="INTEGER" property="number" />
    <result column="photoStyle" jdbcType="VARCHAR" property="photostyle" />
    <result column="photoWidth" jdbcType="INTEGER" property="photowidth" />
    <result column="photoHeight" jdbcType="INTEGER" property="photoheight" />
    <result column="photoLarge" jdbcType="INTEGER" property="photolarge" />
    <result column="photoFlag" jdbcType="TINYINT" property="photoflag" />
    <result column="videoStyle" jdbcType="VARCHAR" property="videostyle" />
    <result column="videoWidth" jdbcType="INTEGER" property="videowidth" />
    <result column="videoHeight" jdbcType="INTEGER" property="videoheight" />
    <result column="videoLarge" jdbcType="INTEGER" property="videolarge" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <where>
      <foreach collection="oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause">
    <where>
      <foreach collection="example.oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List">
    id, name, describe, number, photoStyle, photoWidth, photoHeight, photoLarge, photoFlag, 
    videoStyle, videoWidth, videoHeight, videoLarge
  </sql>
  <select id="selectByExample" parameterType="com.fxy.bean.StyleExample" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from style
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from style
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from style
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <delete id="deleteByExample" parameterType="com.fxy.bean.StyleExample">
    delete from style
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.fxy.bean.Style">
    insert into style (id, name, describe, 
      number, photoStyle, photoWidth, 
      photoHeight, photoLarge, photoFlag, 
      videoStyle, videoWidth, videoHeight, 
      videoLarge)
    values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{describe,jdbcType=VARCHAR}, 
      #{number,jdbcType=INTEGER}, #{photostyle,jdbcType=VARCHAR}, #{photowidth,jdbcType=INTEGER}, 
      #{photoheight,jdbcType=INTEGER}, #{photolarge,jdbcType=INTEGER}, #{photoflag,jdbcType=TINYINT}, 
      #{videostyle,jdbcType=VARCHAR}, #{videowidth,jdbcType=INTEGER}, #{videoheight,jdbcType=INTEGER}, 
      #{videolarge,jdbcType=INTEGER})
  </insert>
  <insert id="insertSelective" parameterType="com.fxy.bean.Style">
    insert into style
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="name != null">
        name,
      </if>
      <if test="describe != null">
        describe,
      </if>
      <if test="number != null">
        number,
      </if>
      <if test="photostyle != null">
        photoStyle,
      </if>
      <if test="photowidth != null">
        photoWidth,
      </if>
      <if test="photoheight != null">
        photoHeight,
      </if>
      <if test="photolarge != null">
        photoLarge,
      </if>
      <if test="photoflag != null">
        photoFlag,
      </if>
      <if test="videostyle != null">
        videoStyle,
      </if>
      <if test="videowidth != null">
        videoWidth,
      </if>
      <if test="videoheight != null">
        videoHeight,
      </if>
      <if test="videolarge != null">
        videoLarge,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=INTEGER},
      </if>
      <if test="name != null">
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="describe != null">
        #{describe,jdbcType=VARCHAR},
      </if>
      <if test="number != null">
        #{number,jdbcType=INTEGER},
      </if>
      <if test="photostyle != null">
        #{photostyle,jdbcType=VARCHAR},
      </if>
      <if test="photowidth != null">
        #{photowidth,jdbcType=INTEGER},
      </if>
      <if test="photoheight != null">
        #{photoheight,jdbcType=INTEGER},
      </if>
      <if test="photolarge != null">
        #{photolarge,jdbcType=INTEGER},
      </if>
      <if test="photoflag != null">
        #{photoflag,jdbcType=TINYINT},
      </if>
      <if test="videostyle != null">
        #{videostyle,jdbcType=VARCHAR},
      </if>
      <if test="videowidth != null">
        #{videowidth,jdbcType=INTEGER},
      </if>
      <if test="videoheight != null">
        #{videoheight,jdbcType=INTEGER},
      </if>
      <if test="videolarge != null">
        #{videolarge,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.fxy.bean.StyleExample" resultType="java.lang.Integer">
    select count(*) from style
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    update style
    <set>
      <if test="record.id != null">
        id = #{record.id,jdbcType=INTEGER},
      </if>
      <if test="record.name != null">
        name = #{record.name,jdbcType=VARCHAR},
      </if>
      <if test="record.describe != null">
        describe = #{record.describe,jdbcType=VARCHAR},
      </if>
      <if test="record.number != null">
        number = #{record.number,jdbcType=INTEGER},
      </if>
      <if test="record.photostyle != null">
        photoStyle = #{record.photostyle,jdbcType=VARCHAR},
      </if>
      <if test="record.photowidth != null">
        photoWidth = #{record.photowidth,jdbcType=INTEGER},
      </if>
      <if test="record.photoheight != null">
        photoHeight = #{record.photoheight,jdbcType=INTEGER},
      </if>
      <if test="record.photolarge != null">
        photoLarge = #{record.photolarge,jdbcType=INTEGER},
      </if>
      <if test="record.photoflag != null">
        photoFlag = #{record.photoflag,jdbcType=TINYINT},
      </if>
      <if test="record.videostyle != null">
        videoStyle = #{record.videostyle,jdbcType=VARCHAR},
      </if>
      <if test="record.videowidth != null">
        videoWidth = #{record.videowidth,jdbcType=INTEGER},
      </if>
      <if test="record.videoheight != null">
        videoHeight = #{record.videoheight,jdbcType=INTEGER},
      </if>
      <if test="record.videolarge != null">
        videoLarge = #{record.videolarge,jdbcType=INTEGER},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    update style
    set id = #{record.id,jdbcType=INTEGER},
      name = #{record.name,jdbcType=VARCHAR},
      describe = #{record.describe,jdbcType=VARCHAR},
      number = #{record.number,jdbcType=INTEGER},
      photoStyle = #{record.photostyle,jdbcType=VARCHAR},
      photoWidth = #{record.photowidth,jdbcType=INTEGER},
      photoHeight = #{record.photoheight,jdbcType=INTEGER},
      photoLarge = #{record.photolarge,jdbcType=INTEGER},
      photoFlag = #{record.photoflag,jdbcType=TINYINT},
      videoStyle = #{record.videostyle,jdbcType=VARCHAR},
      videoWidth = #{record.videowidth,jdbcType=INTEGER},
      videoHeight = #{record.videoheight,jdbcType=INTEGER},
      videoLarge = #{record.videolarge,jdbcType=INTEGER}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.fxy.bean.Style">
    update style
    <set>
      <if test="name != null">
        name = #{name,jdbcType=VARCHAR},
      </if>
      <if test="describe != null">
        describe = #{describe,jdbcType=VARCHAR},
      </if>
      <if test="number != null">
        number = #{number,jdbcType=INTEGER},
      </if>
      <if test="photostyle != null">
        photoStyle = #{photostyle,jdbcType=VARCHAR},
      </if>
      <if test="photowidth != null">
        photoWidth = #{photowidth,jdbcType=INTEGER},
      </if>
      <if test="photoheight != null">
        photoHeight = #{photoheight,jdbcType=INTEGER},
      </if>
      <if test="photolarge != null">
        photoLarge = #{photolarge,jdbcType=INTEGER},
      </if>
      <if test="photoflag != null">
        photoFlag = #{photoflag,jdbcType=TINYINT},
      </if>
      <if test="videostyle != null">
        videoStyle = #{videostyle,jdbcType=VARCHAR},
      </if>
      <if test="videowidth != null">
        videoWidth = #{videowidth,jdbcType=INTEGER},
      </if>
      <if test="videoheight != null">
        videoHeight = #{videoheight,jdbcType=INTEGER},
      </if>
      <if test="videolarge != null">
        videoLarge = #{videolarge,jdbcType=INTEGER},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.fxy.bean.Style">
    update style
    set name = #{name,jdbcType=VARCHAR},
      describe = #{describe,jdbcType=VARCHAR},
      number = #{number,jdbcType=INTEGER},
      photoStyle = #{photostyle,jdbcType=VARCHAR},
      photoWidth = #{photowidth,jdbcType=INTEGER},
      photoHeight = #{photoheight,jdbcType=INTEGER},
      photoLarge = #{photolarge,jdbcType=INTEGER},
      photoFlag = #{photoflag,jdbcType=TINYINT},
      videoStyle = #{videostyle,jdbcType=VARCHAR},
      videoWidth = #{videowidth,jdbcType=INTEGER},
      videoHeight = #{videoheight,jdbcType=INTEGER},
      videoLarge = #{videolarge,jdbcType=INTEGER}
    where id = #{id,jdbcType=INTEGER}
  </update>
  
  <!--查询全部样式信息  -->
  <select id="queryAll" parameterType="com.fxy.bean.Style" resultMap="BaseResultMap">
    select * from style;
  </select>
  
  <!--查询上传一个图片的样式信息  -->
  <select id="selectByCount" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select 
    photoWidth,photoHeight,photoLarge
    from style
    where number = #{i,jdbcType=INTEGER}
  </select>
  
  <!--查Style表样式的对应数量number  -->
  <select id="queryNumber" parameterType="com.fxy.bean.Style" resultMap="BaseResultMap">
    select 
    number
    from style
  </select>
  
  <!-- photoFlag:1 大图    0是小图、组图、视频2    -1 视频1 -->
  <select id="selectByNumber" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select 
    photoFlag
    from style
    where number = #{number,jdbcType=INTEGER}
  </select>
  
  <!-- 获得number、flag对应的样式的id -->
  <select id="selectByNumFlag" parameterType="map" resultMap="BaseResultMap">
    select 
    id
    from style
    where number = #{number,jdbcType=INTEGER}
   	 and  photoFlag = #{flag,jdbcType=TINYINT}
  </select>
  
  <!--根据idStyle获得该样式的数据  -->
  <select id="queryById" parameterType="com.fxy.bean.Style" resultMap="BaseResultMap">
    select 
    *
    from style
    where id = #{idStyle,jdbcType=INTEGER}
  </select>
  
  
  <!--通过number获得样式id -->
  <select id="findIdByNum" parameterType="java.lang.Integer" resultType="java.lang.Integer">
    select 
    id
    from style
    where number = #{number,jdbcType=INTEGER}
  </select>
  
  
  <!-- 获得number、flag对应的样式的id -->
  <select id="findIdByNumFlag" parameterType="map" resultType="java.lang.Integer">
    select 
    id
    from style
    where number = #{number,jdbcType=INTEGER}
   	 and  photoFlag = #{flag,jdbcType=TINYINT}
  </select>
  
</mapper>


完整项目过几天再上传到Git吧


评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值