Category Management
Features:
Gets node
Add a node
change name
Obtaining classification ID
Recursive sub-node ID
interface:
Note:
1 before the operation of the function, to conduct safety tests, such as: whether to log on (using the session); administrator privileges (check the value of the role); parameter is empty; the user logs MD5 encrypted passwords;
2 the Set <the Category>: Use set collection, Category and equal to override hashcode
learning target
Recursive queries child node
Commodity Management:
Features:
Front features: product search, dynamic ordered list of product details, paging function
Back-office functions: product list, product search, upload pictures, upload rich text, product information, merchandise from top to bottom shelf, increasing commodity, commodity update
interface:
Front Interface: 1 dynamic product search and sort list; 2 Product detail;
Background Interface: 1 Product list; 2 product search; 3 upload pictures; 4 product details; 5 frame up and down the product; 6 new products or modify the product; 7 rich text upload pictures
Note:
1:00 write business logic, or other parameters to check, if the check is not through direct return, then check to write business logic
learning target:
Docking 0 FTP services
1. MultipartFile upload files arrive upload web-app directory of the project after the release, then upload files to ftp server, and then delete the web-app directory upload a file inside
1 SpringMVC file upload:
SpringMVC file upload: 1 First create FileServiceImpl, used to upload files, create FTPUtil 2 is used to create uploaded to an FTP server, and then upload it to 3 inside the web-app file deletion
package com.eshop.service.impl; import com.eshop.service.IFileService; import com.eshop.util.FTPUtil; import com.google.common.collect.Lists; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; import java.io.File; import java.io.IOException; import java.util.UUID; @Service("iFileService") public class FileServiceImpl implements IFileService { private static Logger logger= LoggerFactory.getLogger(FileServiceImpl.class); @Override public String upload (MultipartFile file, String path){ //文件名 File.getOriginalFilename fileName = String (); // extensions ---- abc.jpg> JPG String fileExtensionName = fileName.substring (fileName.lastIndexOf () + 1 "."); // to upload the file name String uploadFileName UUID.randomUUID = () toString () + + fileExtensionName;. "." logger.info ( "start upload file upload folder name: {}, upload path: {}, new folder name: {}", fileName, path, uploadFileName); // there is no judge this folder is not created file filedir = new new file (path); ! IF (fileDir.exists ()) { // create a folder before, to open writable permissions prevent tomcat no permission to open fileDir.setWritable (to true); fileDir.mkdirs (); } // create a complete file file.transferTo(targetFile); file targetFile = new file (path, uploadFileName); {the try // file upload has finished // uploading to the FTP server targetfile above FTPUtil.uploadFile (Lists.newArrayList (targetfile)); // after upload, delete the targetfile targetFile.delete (); } the catch (IOException E) { logger.error ( "upload files abnormal", E); return null; } return targetFile.getName (); } }
package com.eshop.util; import org.apache.commons.net.ftp.FTPClient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.util.List; public class FTPUtil { private static Logger logger= LoggerFactory.getLogger(FTPUtil.class); private static String ftpIp =PropertiesUtil.getProperty("ftp.server.ip"); private static String ftpUser =PropertiesUtil.getProperty("ftp.user"); private static String ftpPass =PropertiesUtil.getProperty("ftp.pass"); private String ip; private int port; private String user; pwd String Private; Private FTPClient ftpClient; / ** * * @param IP * @param port Port * @param User * @param pwd * / public FTPUtil (String IP, Port int, User String, String pwd) { this.ip IP =; this.port = Port; this.user = User; this.pwd = pwd; } / ** static method developed out * uploaded file * @param the fileList * @return * / public static Boolean the uploadFile (List < File> the fileList) throws IOException { FTPUtil ftpUtil = new new FTPUtil (ftpIp, 21 is, ftpuser, ftpPass); logger.info ( "FTP server connection start"); Boolean ftpUtil.uploadFile Result = ( "IMG", the fileList); logger.info ( "connection end server, the upload result is: {}", Result); return Result; } / ** * DETAILED logic upload file * @param remotePath remote path: Linux FTP server is inside a folder, If you want to upload a file into this folder below the folder, then use remotePath * @param fileList * @return * / Private boolean uploadFile (String remotePath, List <file> fileList) throws IOException { boolean = uploaded to true; FileInputStream FIS null =; // ftp server connection IF (ConnectServer (this.ip, this.port, this.user, this.pwd)) { the try { // switch working directory ftpClient.setBufferSize (1024); ftpClient .changeWorkingDirectory (remotePath); // set the buffer // set the encoding ftpClient.setControlEncoding ( "UTP-. 8"); // file type to file type binary ftpClient.setFileType (FTPClient.BINARY_FILE_TYPE); // switch operating mode ftpClient.enterLocalPassiveMode () ; / * start uploading files to ftp! ! ! * / For (File FileItem: the fileList) { FIS new new = the FileInputStream (FileItem); ftpClient.storeFile (fileItem.getName (), FIS); } } the catch (IOException E) { logger.error ( "upload files abnormal", e ); uploaded The = to false; } {the finally // close the resource fis.close (); ftpClient.disconnect(); } } return uploaded; } private boolean connectServer(String ip, int port, String user, String pwd){ boolean isSuccess=false; ftpClient=new FTPClient(); try { ftpClient.connect(ip,port); isSuccess=ftpClient.login(user,pwd); } catch (IOException e) { logger.error("连接FTP服务器异常",e); } return isSuccess; } public String getIp() { return ip; } public void setIp(String ip) { this.ip = ip; } public int getPort() { return port; } public void setPort(int port) { this.port = port; } public String getUser() { return user; } public void setUser(String user) { this.user = user; } public String getPwd() { return pwd; } public void setPwd(String pwd) { this.pwd = pwd; } public FTPClient getFtpClient() { return ftpClient; } public void setFtpClient(FTPClient ftpClient) { this.ftpClient = ftpClient; } }
application:
@RequestMapping("upload.do") @ResponseBody public ServerResponce upload(HttpSession session,@RequestParam(name = "upload_name",required = false) MultipartFile file, HttpServletRequest request){ User user=(User)session.getAttribute(Const.CURRENT_USER); if(user==null){ //强制用户登录 return ServerResponce.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(),"用户未登录,请登录"); } if(iUserService.checkAdminRole(user).isSuccess()){ //填充业务 String path=request.getSession().getServletContext().getRealPath("upload"); String targetFileName = iFileService.upload(file, path); String url= PropertiesUtil.getProperty("ftp.server.http.prefix")+targetFileName; Map fileMap= Maps.newHashMap(); fileMap.put("uri",targetFileName); fileMap.put("url",url); return ServerResponce.createBySuccess(fileMap); }else { return ServerResponce.createByErrorMessage("无权限操作"); } }
Flow Properties 2 reads the configuration file:
com.eshop.util Package; Import org.apache.commons.lang3.StringUtils; Import org.slf4j.Logger; Import org.slf4j.LoggerFactory; Import java.io.IOException; Import the java.io.InputStreamReader; Import Classes in java.util .properties; public class PropertiesUtil { Private static Logger Logger = LoggerFactory.getLogger (PropertiesUtil.class); Private static the Properties Properties; / * static code block (only once) is superior to the ordinary block structure is superior to the code block * / static { fileName = String "eshop.properties"; Properties new new = the Properties (); the try { Properties.load (. the InputStreamReader new new (PropertiesUtil.class.getClassLoader () the getResourceAsStream (fileName), "UTF-. 8")); The catch} (IOException E) { logger.error ( "abnormal profile read", E); } } / ** * profile value obtained inside * @param Key * @return * / public static String getProperty (String Key ) { // avoid spaces left key, trim () strips spaces String value = Properties.getProperty (key.trim ()); IF (StringUtils.isBlank (value)) { return null; } return value.trim (); } public static String getProperty (String key, String defaultVaule) { // avoid spaces left key, trim () strips spaces String value = properties.getProperty (key.trim () ); if(StringUtils.isBlank(value)){ return defaultVaule; } return value.trim(); } }
3 abstract POJO, BO, conversion relationship VO objects and Solutions
4 joda-time Quick Start
com.eshop.util Package; 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 use of the time to process //1.string -> 2. DATE DATE -> String Private STANDARD_FORMAT static String = "the mM-dd-YYYY HH: mm : SS "; / ** * means for time string format, the incoming event a format * @param dateTimeStr * @param formatStr event format * @return * / public static StrToDate a Date (dateTimeStr string, 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 * @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); } }
5 static block
Static code block (only once) is superior to the ordinary block structure is superior to the code block
6 Mybatis-PageHelper paging and dynamic ordering
7 Mybatis list traverse the set of methods
8 Mybatis dynamic assembly of where statements