请先登录
14 |
Title: IDUtils
8 | *Description:
9 | *Company: www.itcast.com
10 | * @author 入云龙 11 | * @date 2015年7月22日下午2:32:10 12 | * @version 1.0 13 | */ 14 | public class IDUtils { 15 | 16 | /** 17 | * 图片名生成 18 | */ 19 | public static String genImageName() { 20 | //取当前时间的长整形值包含毫秒 21 | long millis = System.currentTimeMillis(); 22 | //long millis = System.nanoTime(); 23 | //加上三位随机数 24 | Random random = new Random(); 25 | int end3 = random.nextInt(999); 26 | //如果不足三位前面补0 27 | String str = millis + String.format("%03d", end3); 28 | 29 | return str; 30 | } 31 | 32 | /** 33 | * 商品id生成 34 | */ 35 | public static long genItemId() { 36 | //取当前时间的长整形值包含毫秒 37 | long millis = System.currentTimeMillis(); 38 | //long millis = System.nanoTime(); 39 | //加上两位随机数 40 | Random random = new Random(); 41 | int end2 = random.nextInt(99); 42 | //如果不足两位前面补0 43 | String str = millis + String.format("%02d", end2); 44 | long id = new Long(str); 45 | return id; 46 | } 47 | 48 | public static void main(String[] args) { 49 | for(int i=0;i< 100;i++) 50 | System.out.println(genItemId()); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/koali/web/MainController.java: -------------------------------------------------------------------------------- 1 | package com.koali.web; 2 | 3 | import com.koali.entity.Picture; 4 | import com.koali.entity.User; 5 | import com.koali.service.PictureService; 6 | import com.koali.service.UserService; 7 | import org.apache.commons.io.FileUtils; 8 | import org.apache.ibatis.annotations.Param; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.stereotype.Controller; 11 | import org.springframework.ui.Model; 12 | import org.springframework.web.bind.annotation.RequestMapping; 13 | import org.springframework.web.bind.annotation.RequestMethod; 14 | import org.springframework.web.bind.annotation.RequestParam; 15 | import org.springframework.web.multipart.MultipartFile; 16 | 17 | import javax.servlet.http.HttpServletRequest; 18 | import javax.servlet.http.HttpSession; 19 | import java.io.File; 20 | import java.io.IOException; 21 | import java.util.Date; 22 | import java.util.List; 23 | 24 | /** 25 | * Created by Elric on 2017/3/24. 26 | */ 27 | @Controller 28 | public class MainController { 29 | @Autowired 30 | private PictureService pictureService; 31 | @Autowired 32 | private UserService userService; 33 | @RequestMapping(value = "/") 34 | public String index(Model model){ 35 | List