docs(项目): 完善代码注释

master
wayn 5 years ago
parent 4bb46bcb98
commit 76c87d989a

@ -7,6 +7,9 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
*
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Log {

@ -16,6 +16,9 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
/**
*
*/
@Slf4j
public class BaseController {

@ -9,6 +9,9 @@ import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* entity
*/
@Data
public class BaseEntity implements Serializable {
private static final long serialVersionUID = 1956057929467119856L;

@ -6,8 +6,7 @@ import com.wayn.common.util.file.FileUploadUtil;
import com.wayn.common.util.file.FileUtils;
import com.wayn.common.util.http.HttpUtil;
import com.wayn.framework.config.WaynConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
@ -20,14 +19,14 @@ import javax.servlet.http.HttpServletResponse;
import java.io.File;
/**
*
*
*
* @author ruoyi
*/
@Slf4j
@Controller
@RequestMapping("common")
public class CommonController {
private static final Logger log = LoggerFactory.getLogger(CommonController.class);
/**
*
@ -36,19 +35,17 @@ public class CommonController {
* @param delete
*/
@GetMapping("download")
public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request) {
public void fileDownload(String fileName, boolean delete, HttpServletResponse response, HttpServletRequest request) {
try {
if (!FileUtils.isValidFilename(fileName)) {
throw new BusinessException("文件名称(" + fileName + ")非法,不允许下载。 ");
}
String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);
String filePath = WaynConfig.getDownloadPath() + fileName;
response.setCharacterEncoding("utf-8");
response.setContentType("multipart/form-data");
response.setHeader("Content-Disposition",
"attachment;fileName=" + FileUtils.setFileDownloadHeader(request, realFileName));
response.setHeader("Content-Disposition", "attachment;fileName=" + FileUtils.setFileDownloadHeader(request, realFileName));
FileUtils.writeBytes(filePath, response.getOutputStream());
if (delete) {
FileUtils.deleteFile(filePath);

@ -43,6 +43,16 @@ public class GlobalExceptionHandler {
return R.error(e.getMessage());
}
/**
*
*/
@ExceptionHandler(MethodArgumentNotValidException.class)
public R validExceptionHandler(MethodArgumentNotValidException e) {
log.error(e.getMessage(), e);
String message = Objects.requireNonNull(e.getBindingResult().getFieldError()).getDefaultMessage();
return R.error(message);
}
/**
*
*/
@ -78,14 +88,4 @@ public class GlobalExceptionHandler {
log.error(e.getMessage(), e);
return R.error(e.getMessage());
}
/**
*
*/
@ExceptionHandler(MethodArgumentNotValidException.class)
public R validExceptionHandler(MethodArgumentNotValidException e) {
log.error(e.getMessage(), e);
String message = e.getBindingResult().getFieldError().getDefaultMessage();
return R.error(message);
}
}

@ -14,7 +14,7 @@ import java.util.Map;
*/
public class ParameterUtil {
private static final String BASE_ENTITY = "BaseEntity";
private static ThreadLocal<QueryWrapper> entityWrapperThreadLocal = new ThreadLocal<>();
private static final ThreadLocal<QueryWrapper> entityWrapperThreadLocal = new ThreadLocal<>();
/**
* wrapper
@ -22,7 +22,7 @@ public class ParameterUtil {
* @param <T>
*/
public static <T> void setWrapper() {
QueryWrapper<T> wrapper = new QueryWrapper<T>();
QueryWrapper<T> wrapper = new QueryWrapper<>();
String startTime = ServletUtils.getParameter("startTime");
String endTime = ServletUtils.getParameter("endTime");
ServletUtils.setParameter("startTime", startTime);

@ -58,10 +58,8 @@ public class ExcelUtil {
String filename = ExcelUtil.encodingFilename(originalName);
try (OutputStream out = new FileOutputStream(ExcelUtil.getAbsoluteFile(filename))) {
workbook.write(out);
} catch (FileNotFoundException e) {
} catch (IOException e) {
log.error(e.getMessage(), e);
} catch (IOException exception) {
log.error(exception.getMessage(), exception);
}
return filename;
}

@ -8,6 +8,7 @@ import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
import java.util.Objects;
/**
*
@ -15,14 +16,14 @@ import java.io.IOException;
public class FileUploadUtil {
public static String uploadFile(MultipartFile file, String filePath) throws IOException {
int fileNameLength = file.getOriginalFilename().length();
int fileNameLength = Objects.requireNonNull(file.getOriginalFilename()).length();
if (fileNameLength > 100) {
throw new BusinessException("文件名称过长");
}
String fileName = file.getOriginalFilename();
String extension = FilenameUtils.getExtension(fileName);
if (StringUtils.isEmpty(extension)) {
extension = MimeTypeUtils.getExtension(file.getContentType());
extension = MimeTypeUtils.getExtension(Objects.requireNonNull(file.getContentType()));
}
String encodingFilename = FileUtils.encodingFilename(fileName);
fileName = DateUtils.datePath() + "/" + encodingFilename + "." + extension;

@ -60,7 +60,7 @@ public class FileUtils extends org.apache.commons.io.FileUtils {
*
*
* @param filePath
* @return
* @return boolean
*/
public static boolean deleteFile(String filePath) {
boolean flag = false;

@ -50,7 +50,7 @@ public class HttpUtil {
* </p>
*
* @param request
* @return
* @return boolean
*/
public static boolean isAjax(HttpServletRequest request) {
return "XMLHttpRequest".equals(request.getHeader("X-Requested-With"));
@ -299,12 +299,12 @@ public class HttpUtil {
request.getContextPath();
}
public static String getValueByCookie(HttpServletRequest request) {
public static String getValueByCookie(String key, HttpServletRequest request) {
String value = "";
Cookie[] cookies = request.getCookies();
if (Objects.nonNull(cookies)) {
for (Cookie cookie : cookies) {
if (cookie.getName().equals("token")) {
if (cookie.getName().equals(key)) {
value = cookie.getValue();
break;
}

@ -36,8 +36,8 @@ public class JwtUtil {
/**
*
*
* @param token
* @return
* @param token token
* @return
*/
public static Date getIssuedAt(String token) {
try {

@ -8,7 +8,6 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.transaction.annotation.EnableTransactionManagement;
//Spring boot方式
@EnableTransactionManagement
@EnableAspectJAutoProxy
@Configuration

@ -15,6 +15,9 @@ import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import java.util.List;
/**
* sys_user
*/
@Data
@ApiModel("用户实体")
@EqualsAndHashCode(callSuper = true)

Loading…
Cancel
Save