From 6f95d5ed3e91b264cc3bd9bbb997822f67419e4b Mon Sep 17 00:00:00 2001 From: Keven Date: Mon, 22 Apr 2019 18:43:55 +0800 Subject: [PATCH 01/13] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=9C=A8=E7=BA=BFmysql?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E5=92=8CRedis?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application-pro.properties | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/resources/application-pro.properties b/src/main/resources/application-pro.properties index 720dea0..761aad8 100644 --- a/src/main/resources/application-pro.properties +++ b/src/main/resources/application-pro.properties @@ -2,9 +2,9 @@ # MySQL connection config # ============================== spring.datasource.driverClassName = com.mysql.cj.jdbc.Driver -spring.datasource.url = jdbc:mysql://localhost:3306/forum?serverTimezone=GMT&useSSL=false&useUnicode=true&characterEncoding=UTF-8 -spring.datasource.username = root -spring.datasource.password = root +spring.datasource.url = jdbc:mysql://www.polysys.cn:13306/fs_forum?serverTimezone=GMT&useSSL=false&useUnicode=true&characterEncoding=UTF-8 +spring.datasource.username = fstack +spring.datasource.password = fstack spring.datasource.type=com.zaxxer.hikari.HikariDataSource spring.datasource.hikari.minimum-idle=5 spring.datasource.hikari.maximum-pool-size=15 @@ -19,9 +19,9 @@ spring.datasource.hikari.connection-test-query=SELECT 1 # Redis configuration # ============================== spring.redis.database=0 -spring.redis.host=192.168.1.129 +spring.redis.host=www.polysys.cn spring.redis.port=6379 -spring.redis.password=kaixin +spring.redis.password=fstack spring.redis.timeout=5000ms spring.redis.lettuce.pool.max-idle=10 spring.redis.lettuce.pool.min-idle=5 -- Gitee From a140437eb7c1c0fa446ac345a4215906b5cf4ee1 Mon Sep 17 00:00:00 2001 From: Keven Date: Tue, 23 Apr 2019 21:33:19 +0800 Subject: [PATCH 02/13] =?UTF-8?q?=E9=9D=99=E6=80=81=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E5=8F=8A=E5=A4=B4=E5=83=8F=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fstack/config/GlobalExceptionHandler.java | 48 +++ .../fstack/config/StaticResourceConfig.java | 4 - .../fstack/security/WebSecurityConfig.java | 85 +++-- .../com/fstack/service/StorageService.java | 9 +- .../service/impl/StorageServiceImpl.java | 59 ++- .../fstack/service/impl/UserServiceImpl.java | 352 +++++++++--------- src/main/resources/application.properties | 6 +- src/main/resources/templates/forum/post.html | 2 +- .../templates/forum/user-profile.html | 2 +- .../templates/forum/user-settings.html | 6 +- .../templates/fragments/comments.html | 2 +- .../templates/fragments/posts-list.html | 127 +++---- 12 files changed, 363 insertions(+), 339 deletions(-) create mode 100644 src/main/java/com/fstack/config/GlobalExceptionHandler.java diff --git a/src/main/java/com/fstack/config/GlobalExceptionHandler.java b/src/main/java/com/fstack/config/GlobalExceptionHandler.java new file mode 100644 index 0000000..36d3188 --- /dev/null +++ b/src/main/java/com/fstack/config/GlobalExceptionHandler.java @@ -0,0 +1,48 @@ +package com.fstack.config; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.Enumeration; + +/** + * @author Hu Jie + * @date 2019/04/23 10:21 AM + */ +@ControllerAdvice +public class GlobalExceptionHandler { + private Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class); + + /** + * 捕获具体指定外的所有异常 + * + * @param ex + * @param request + * @param response + */ + @ExceptionHandler(value = Exception.class) + private void handle(Exception ex, HttpServletRequest request, HttpServletResponse response) { + logger.error("***** GlobalException Start *****"); + logger.error("Exception:{}", ex.toString()); + logger.error("Message:{}", ex.getMessage()); + logger.error("Request Url:{}", request.getRequestURL()); + Enumeration enumeration = request.getParameterNames(); + logger.error("Parameters:"); + while (enumeration.hasMoreElements()) { + String name = enumeration.nextElement().toString(); + logger.error("[{}]:[{}]", name, request.getParameter(name)); + } + StackTraceElement[] error = ex.getStackTrace(); + for (StackTraceElement stackTraceElement : error) { + logger.error("StackTrace:{}", stackTraceElement.toString()); + } + + logger.error("***** GlobalException End *****"); + } + + +} diff --git a/src/main/java/com/fstack/config/StaticResourceConfig.java b/src/main/java/com/fstack/config/StaticResourceConfig.java index 914b847..3f9d205 100644 --- a/src/main/java/com/fstack/config/StaticResourceConfig.java +++ b/src/main/java/com/fstack/config/StaticResourceConfig.java @@ -19,10 +19,6 @@ public class StaticResourceConfig implements WebMvcConfigurer { public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/avatar/**") .addResourceLocations("file:" + staticResourceLocation); - - registry.addResourceHandler("/static/**") - .addResourceLocations("classpath:/static/"); - WebMvcConfigurer.super.addResourceHandlers(registry); } @Override diff --git a/src/main/java/com/fstack/security/WebSecurityConfig.java b/src/main/java/com/fstack/security/WebSecurityConfig.java index b837eec..2c39344 100644 --- a/src/main/java/com/fstack/security/WebSecurityConfig.java +++ b/src/main/java/com/fstack/security/WebSecurityConfig.java @@ -12,6 +12,7 @@ import org.springframework.security.config.annotation.web.configuration.EnableWe import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.crypto.password.PasswordEncoder; /** * @author ab @@ -21,51 +22,49 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; @EnableGlobalMethodSecurity(prePostEnabled = true) public class WebSecurityConfig extends WebSecurityConfigurerAdapter { - @Bean - public BCryptPasswordEncoder bCryptPasswordEncoder() { - return new BCryptPasswordEncoder(); - } + @Bean + public PasswordEncoder passwordEncoder() { + return new BCryptPasswordEncoder(); + } - @Bean - UserDetailsService myUserDetailsService() { // register userDetailsService - return new MyUserDetailsService(); - } + @Bean + UserDetailsService myUserDetailsService() { // register userDetailsService + return new MyUserDetailsService(); + } - @Bean - public AuthenticationProvider authenticationProvider() { - DaoAuthenticationProvider authenticationProvider = new DaoAuthenticationProvider(); - authenticationProvider.setUserDetailsService(this.myUserDetailsService()); - authenticationProvider.setPasswordEncoder(this.bCryptPasswordEncoder()); - return authenticationProvider; - } + @Bean + public AuthenticationProvider authenticationProvider() { + DaoAuthenticationProvider authenticationProvider = new DaoAuthenticationProvider(); + authenticationProvider.setUserDetailsService(this.myUserDetailsService()); + authenticationProvider.setPasswordEncoder(this.passwordEncoder()); + return authenticationProvider; + } - @Autowired - public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { - // auth.inMemoryAuthentication() - // .withUser("t").password("t").roles("USER") - // .and() - // .withUser("admin").password("admin").roles("ADMIN"); + @Autowired + public void configureGlobal(AuthenticationManagerBuilder auth) { + auth.authenticationProvider(this.authenticationProvider()); + } - // auth.userDetailsService(this.myUserDetailsService()).passwordEncoder(this.bCryptPasswordEncoder()); - - auth.authenticationProvider(this.authenticationProvider()); // different approach - } - - @Override - protected void configure(HttpSecurity http) throws Exception { - http.csrf().disable().authorizeRequests().antMatchers("/user/settings").authenticated() // order matters - .antMatchers("/", "/js/**", "/css/**", "/images/**", "/fonts/**", "/bootstrap-select/**", - "/bootstrap-datetimepicker/**", "/custom/**", "/daterangepicker/**", "/chartjs/**") - .permitAll() // these paths are configure not to require any authentication - .antMatchers("/post/**").permitAll() // all posts are allowed to be viewed without authentication - .antMatchers("/user/**").permitAll() // all user profiles are allowed to be viewed without - // authentication - .antMatchers("/category/**").permitAll() // all categories are allowed to be viewed without - // authentication - .antMatchers("/avatar/**").permitAll() // temp - .anyRequest().authenticated() // every request requires the user to be authenticated - .and().formLogin().loginPage("/user/login").permitAll() // login URL can be accessed by anyone - .and().logout().invalidateHttpSession(true).clearAuthentication(true).logoutSuccessUrl("/?logout") - .permitAll(); - } + @Override + protected void configure(HttpSecurity http) throws Exception { + http.csrf().disable().authorizeRequests() + .anyRequest().authenticated() + // all static resource and home page + .antMatchers("/", "/avatar/**", "/", "/js/**", "/css/**", "/images/**", "/fonts/**", "/bootstrap-select/**", + "/bootstrap-datetimepicker/**", "/custom/**", "/daterangepicker/**", "/chartjs/**").permitAll() + .antMatchers("/user/**").permitAll() + .antMatchers("/user/settings").authenticated() + // all posts are allowed to be viewed without authentication + .antMatchers("/post/**").permitAll() + // all user profiles are allowed to be viewed without authentication + .antMatchers("/user/**").permitAll() + // all categories are allowed to be viewed without authentication + .antMatchers("/category/**").permitAll() + // login URL can be accessed by anyone + .and() + .formLogin().loginPage("/user/login").permitAll() + .and() + .logout().invalidateHttpSession(true).clearAuthentication(true).logoutSuccessUrl("/?logout") + .permitAll(); + } } \ No newline at end of file diff --git a/src/main/java/com/fstack/service/StorageService.java b/src/main/java/com/fstack/service/StorageService.java index 6b309f4..781090f 100644 --- a/src/main/java/com/fstack/service/StorageService.java +++ b/src/main/java/com/fstack/service/StorageService.java @@ -1,15 +1,14 @@ package com.fstack.service; -import org.springframework.web.multipart.MultipartFile; - import com.fstack.persistence.model.User; +import org.springframework.web.multipart.MultipartFile; public interface StorageService { - void init(); + void init(); - User store(MultipartFile file, String path); + User store(MultipartFile file, String path); - void deleteAll(); + void deleteAll(); } \ No newline at end of file diff --git a/src/main/java/com/fstack/service/impl/StorageServiceImpl.java b/src/main/java/com/fstack/service/impl/StorageServiceImpl.java index 4aefd2b..ff15111 100644 --- a/src/main/java/com/fstack/service/impl/StorageServiceImpl.java +++ b/src/main/java/com/fstack/service/impl/StorageServiceImpl.java @@ -1,8 +1,9 @@ package com.fstack.service.impl; -import java.io.IOException; -import java.nio.file.*; - +import com.fstack.exception.StorageException; +import com.fstack.persistence.dao.UserMapper; +import com.fstack.persistence.model.User; +import com.fstack.service.StorageService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -11,10 +12,10 @@ import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; import org.springframework.web.multipart.MultipartFile; -import com.fstack.exception.StorageException; -import com.fstack.persistence.dao.UserMapper; -import com.fstack.persistence.model.User; -import com.fstack.service.StorageService; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; @Service("storageService") public class StorageServiceImpl implements StorageService { @@ -27,6 +28,15 @@ public class StorageServiceImpl implements StorageService { @Autowired private UserMapper userMapper; + @Override + public void init() { + try { + Files.createDirectories(Paths.get(this.staticResourceLocation)); + } catch (Exception e) { + throw new StorageException("Could not initialize storage", e); + } + } + @Override public User store(MultipartFile file, String username) { // re-factor needed if (null == file || file.isEmpty() || null == username || username.isEmpty() || username.equalsIgnoreCase("")) { @@ -34,47 +44,20 @@ public class StorageServiceImpl implements StorageService { } String filename = StringUtils.cleanPath(file.getOriginalFilename()); try { - if (filename.contains("..")) { - throw new StorageException("Cannot store file with relative path outside current directory " + filename); - } - Path dir = Paths.get(this.staticResourceLocation + "/" + username); - createSingleDirectory(dir); - Path avatarLocation = Paths.get(this.staticResourceLocation + "/" + username).resolve(filename); + String path = username + "/" + filename; + Path avatarLocation = Paths.get(this.staticResourceLocation + "/" + path); + Files.createDirectories(avatarLocation); Files.copy(file.getInputStream(), avatarLocation, StandardCopyOption.REPLACE_EXISTING); logger.info("Saved file to >> " + avatarLocation); // update user avatar location User user = this.userMapper.findByUsername(username); - //user.setAvatarLocation("avatar/" + username + "/" + filename); - user.setAvatarLocation(avatarLocation.toAbsolutePath().toString()); + user.setAvatarLocation(path); return user; } catch (Exception e) { throw new StorageException("Failed to store file " + filename, e); } } - private void createSingleDirectory(Path path) { - try { - Files.createDirectory(path); - path = path.toAbsolutePath(); - System.out.println("\n" + path + " directory created."); - } catch (NoSuchFileException e) { - System.out.println("\nDirectory creation failed:\n" + e); - } catch (FileAlreadyExistsException e) { - System.out.println("\nDirectory creation failed:\n" + e); - } catch (IOException e) { - System.out.println("\nDirectory creation failed:\n" + e); - } - } - - @Override - public void init() { - try { - Files.createDirectories(Paths.get(this.staticResourceLocation)); - } catch (Exception e) { - throw new StorageException("Could not initialize storage", e); - } - } - @Override public void deleteAll() { diff --git a/src/main/java/com/fstack/service/impl/UserServiceImpl.java b/src/main/java/com/fstack/service/impl/UserServiceImpl.java index 37182b0..5ec7957 100644 --- a/src/main/java/com/fstack/service/impl/UserServiceImpl.java +++ b/src/main/java/com/fstack/service/impl/UserServiceImpl.java @@ -1,22 +1,5 @@ package com.fstack.service.impl; -import java.sql.Timestamp; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationEventPublisher; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; -import org.springframework.stereotype.Service; - import com.fstack.event.OnRegistrationCompleteEvent; import com.fstack.persistence.dao.CommentMapper; import com.fstack.persistence.dao.PostMapper; @@ -30,169 +13,184 @@ import com.fstack.service.StorageService; import com.fstack.service.UserService; import com.fstack.web.dto.UserRegistrationDto; import com.fstack.web.dto.UserSettingsDto; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.stereotype.Service; + +import javax.servlet.http.HttpServletRequest; +import java.sql.Timestamp; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; @Service("userService") public class UserServiceImpl implements UserService { - private static final Logger logger = LoggerFactory.getLogger(UserServiceImpl.class); - - @Autowired - private UserMapper userMapper; - - @Autowired - private PostMapper postMapper; - - @Autowired - private CommentMapper commentMapper; - - @Autowired - private VerificationTokenMapper verificationTokenMapper; - - @Autowired - private StorageService storageService; - - @Autowired - private BCryptPasswordEncoder bCryptPasswordEncoder; - - @Autowired - private ApplicationEventPublisher evenPublisher; - - @Override - public User findById(Long id) { - return userMapper.findById(id); - } - - @Override - public User findByEmail(String email) { - return userMapper.findByEmail(email); - } - - @Override - public User findByUsername(String username) { - return userMapper.findByUsername(username); - } - - @Override - public int save(User user) { - user.setPassword(bCryptPasswordEncoder.encode(user.getPassword())); - return userMapper.save(user); - } - - @Override - public Map getUserProfileAndPostsByUserIdByTabType(Long userId, String tabType) { - if (null == userId) { - return null; - } - User user = this.userMapper.findById(userId); - if (null == user) { - return null; - } - Map attributes = new HashMap<>(); - attributes.put("user", user); - String activeTab = tabType == null ? "posts" : tabType; - if ("posts".equalsIgnoreCase(activeTab)) { - List posts = this.postMapper.findPostsByUserId(userId); - attributes.put("posts", posts); - } else if ("comments".equalsIgnoreCase(activeTab)) { - List comments = this.commentMapper.findCommentsByUserId(userId); - attributes.put("comments", comments); - } - attributes.put("activeTab", activeTab); - return attributes; - } - - @Override - public User findAuthenticatedUser() { - Authentication auth = SecurityContextHolder.getContext().getAuthentication(); - String username = auth.getName(); - return this.userMapper.findByUsername(username); - } - - @Override - public Map updateUserProfile(UserSettingsDto userSettingsDto) { - Map attributes = new HashMap<>(); - String authenticatedUsername = this.findAuthenticatedUser().getUsername(); - if (null == authenticatedUsername || authenticatedUsername.equalsIgnoreCase("") || null == userSettingsDto - || userSettingsDto.getEmail().isEmpty() || userSettingsDto.getEmail().equals("")) { - attributes.put("uploadResultMessage", "uploadFailure"); - return attributes; - } - - // update user profile - User user = this.storageService.store(userSettingsDto.getAvatar(), authenticatedUsername); - if (null == user) { - attributes.put("uploadResultMessage", "uploadFailure"); - user = this.findAuthenticatedUser(); // find authenticated user if no user found - } - user.setEmail(userSettingsDto.getEmail()); - user.setBio(userSettingsDto.getBio()); - this.userMapper.update(user); - - // return attributes - attributes.put("user", user); - attributes.put("uploadResultMessage", "uploadSuccess"); - return attributes; - } - - @Override - public Map getUserSettingPage() { - User user = this.findAuthenticatedUser(); - UserSettingsDto newUserSettingsForm = new UserSettingsDto(); - newUserSettingsForm.setBio(user.getBio()); - newUserSettingsForm.setEmail(user.getEmail()); - Map attributes = new HashMap<>(); - attributes.put("user", user); - attributes.put("userSettingsDto", newUserSettingsForm); - return attributes; - } - - @Override - public Map registerUserAccount(UserRegistrationDto userDto, HttpServletRequest request) { - Map attributes = new HashMap<>(); - - // save newly registered user - User user = new User(); - user.setPassword(this.bCryptPasswordEncoder.encode(userDto.getPassword())); - user.setUsername(userDto.getUsername()); - user.setEmail(userDto.getEmail()); - user.setDateCreated(new Timestamp(System.currentTimeMillis())); - user.activated(false); - user.setRoles(User.USER); - - // save new user and get number of affected row - int affectedRow = userMapper.save(user); - - // publish registration event - String appUrl = "http://" + request.getServerName() + ":" + request.getServerPort(); - Locale locale = request.getLocale(); - OnRegistrationCompleteEvent event = new OnRegistrationCompleteEvent(user.getUsername(), appUrl, locale); - this.evenPublisher.publishEvent(event); - - // populate attributes - String registrationResult = affectedRow == 1 ? "success" : "failure"; - attributes.put("userRegistrationResult", registrationResult); - return attributes; - } - - @Override - public Map confirmUserRegistrationWithToken(String token) { - Map attributes = new HashMap<>(); - VerificationToken verificationToken = this.verificationTokenMapper.findByToken(token); - if (null == verificationToken) { - return null; // 404 exception - } - // check if expire time is still within 24 hours - boolean tokenValid = verificationToken.getExpiryDate().getTime() - System.currentTimeMillis() > 0; - if (tokenValid) { - String username = verificationToken.getUser().getUsername(); - User user = this.userMapper.findByUsername(username); - user.activated(true); - this.userMapper.update(user); - attributes.put("registrationActivationResult", "success"); - } else { - attributes.put("registrationActivationResult", "failure"); - } - return attributes; - } + private static final Logger logger = LoggerFactory.getLogger(UserServiceImpl.class); + + @Autowired + private UserMapper userMapper; + + @Autowired + private PostMapper postMapper; + + @Autowired + private CommentMapper commentMapper; + + @Autowired + private VerificationTokenMapper verificationTokenMapper; + + @Autowired + private StorageService storageService; + + @Autowired + private PasswordEncoder passwordEncoder; + + @Autowired + private ApplicationEventPublisher evenPublisher; + + @Override + public int save(User user) { + user.setPassword(passwordEncoder.encode(user.getPassword())); + return userMapper.save(user); + } + + @Override + public User findById(Long id) { + return userMapper.findById(id); + } + + @Override + public User findByUsername(String username) { + return userMapper.findByUsername(username); + } + + @Override + public User findByEmail(String email) { + return userMapper.findByEmail(email); + } + + @Override + public User findAuthenticatedUser() { + Authentication auth = SecurityContextHolder.getContext().getAuthentication(); + String username = auth.getName(); + return this.userMapper.findByUsername(username); + } + + @Override + public Map getUserProfileAndPostsByUserIdByTabType(Long userId, String tabType) { + if (null == userId) { + return null; + } + User user = this.userMapper.findById(userId); + if (null == user) { + return null; + } + Map attributes = new HashMap<>(); + attributes.put("user", user); + String activeTab = tabType == null ? "posts" : tabType; + if ("posts".equalsIgnoreCase(activeTab)) { + List posts = this.postMapper.findPostsByUserId(userId); + attributes.put("posts", posts); + } else if ("comments".equalsIgnoreCase(activeTab)) { + List comments = this.commentMapper.findCommentsByUserId(userId); + attributes.put("comments", comments); + } + attributes.put("activeTab", activeTab); + return attributes; + } + + @Override + public Map updateUserProfile(UserSettingsDto userSettingsDto) { + Map attributes = new HashMap<>(); + String authenticatedUsername = this.findAuthenticatedUser().getUsername(); + if (null == authenticatedUsername || authenticatedUsername.equalsIgnoreCase("") || null == userSettingsDto + || userSettingsDto.getEmail().isEmpty() || userSettingsDto.getEmail().equals("")) { + attributes.put("uploadResultMessage", "uploadFailure"); + return attributes; + } + + // update user profile + User user = this.storageService.store(userSettingsDto.getAvatar(), authenticatedUsername); + if (null == user) { + attributes.put("uploadResultMessage", "uploadFailure"); + user = this.findAuthenticatedUser(); // find authenticated user if no user found + } + user.setEmail(userSettingsDto.getEmail()); + user.setBio(userSettingsDto.getBio()); + this.userMapper.update(user); + + // return attributes + attributes.put("user", user); + attributes.put("uploadResultMessage", "uploadSuccess"); + return attributes; + } + + @Override + public Map getUserSettingPage() { + User user = this.findAuthenticatedUser(); + UserSettingsDto newUserSettingsForm = new UserSettingsDto(); + newUserSettingsForm.setBio(user.getBio()); + newUserSettingsForm.setEmail(user.getEmail()); + Map attributes = new HashMap<>(); + attributes.put("user", user); + attributes.put("userSettingsDto", newUserSettingsForm); + return attributes; + } + + @Override + public Map registerUserAccount(UserRegistrationDto userDto, HttpServletRequest request) { + Map attributes = new HashMap<>(); + + // save newly registered user + User user = new User(); + user.setPassword(this.passwordEncoder.encode(userDto.getPassword())); + user.setUsername(userDto.getUsername()); + user.setEmail(userDto.getEmail()); + user.setDateCreated(new Timestamp(System.currentTimeMillis())); + user.activated(false); + user.setRoles(User.USER); + + // save new user and get number of affected row + int affectedRow = userMapper.save(user); + + // publish registration event + String appUrl = "http://" + request.getServerName() + ":" + request.getServerPort(); + Locale locale = request.getLocale(); + OnRegistrationCompleteEvent event = new OnRegistrationCompleteEvent(user.getUsername(), appUrl, locale); + this.evenPublisher.publishEvent(event); + + // populate attributes + String registrationResult = affectedRow == 1 ? "success" : "failure"; + attributes.put("userRegistrationResult", registrationResult); + return attributes; + } + + @Override + public Map confirmUserRegistrationWithToken(String token) { + Map attributes = new HashMap<>(); + VerificationToken verificationToken = this.verificationTokenMapper.findByToken(token); + if (null == verificationToken) { + return null; // 404 exception + } + // check if expire time is still within 24 hours + boolean tokenValid = verificationToken.getExpiryDate().getTime() - System.currentTimeMillis() > 0; + if (tokenValid) { + String username = verificationToken.getUser().getUsername(); + User user = this.userMapper.findByUsername(username); + user.activated(true); + this.userMapper.update(user); + attributes.put("registrationActivationResult", "success"); + } else { + attributes.put("registrationActivationResult", "failure"); + } + return attributes; + } } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index e3cfacf..8ffdf2a 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,5 +1,5 @@ server.port=8080 -spring.profiles.active=dev +spring.profiles.active=pro server.servlet.context-path= / spring.aop.proxy-target-class=true @@ -35,9 +35,9 @@ pagehelper.supportMethodsArguments=true pagehelper.params=count=countSql # ============================== -# avator location +# avatar location, must end with / # ============================== -resource.staticResourceLocation=/avatar +resource.staticResourceLocation=D:/avatar/ spring.output.ansi.enabled=always logging.config=classpath:logback.xml \ No newline at end of file diff --git a/src/main/resources/templates/forum/post.html b/src/main/resources/templates/forum/post.html index 63d0d00..4812780 100644 --- a/src/main/resources/templates/forum/post.html +++ b/src/main/resources/templates/forum/post.html @@ -18,7 +18,7 @@ diff --git a/src/main/resources/templates/forum/user-profile.html b/src/main/resources/templates/forum/user-profile.html index bbbd88f..4c62cd8 100644 --- a/src/main/resources/templates/forum/user-profile.html +++ b/src/main/resources/templates/forum/user-profile.html @@ -12,7 +12,7 @@
profile_pic + th:src="@{'/avatar/'+${user.avatarLocation}}">
diff --git a/src/main/resources/templates/forum/user-settings.html b/src/main/resources/templates/forum/user-settings.html index 5444a0d..2eedb23 100644 --- a/src/main/resources/templates/forum/user-settings.html +++ b/src/main/resources/templates/forum/user-settings.html @@ -62,9 +62,9 @@ $(function() { - - - + + +
当前头像:profile_fileprofile_fileprofile_fileprofile_fileprofile_fileprofile_file
diff --git a/src/main/resources/templates/fragments/comments.html b/src/main/resources/templates/fragments/comments.html index 33f5cca..b472fc5 100644 --- a/src/main/resources/templates/fragments/comments.html +++ b/src/main/resources/templates/fragments/comments.html @@ -10,7 +10,7 @@
diff --git a/src/main/resources/templates/fragments/posts-list.html b/src/main/resources/templates/fragments/posts-list.html index 7901f73..42daa54 100644 --- a/src/main/resources/templates/fragments/posts-list.html +++ b/src/main/resources/templates/fragments/posts-list.html @@ -1,74 +1,75 @@ -
- -
-
-
-
-
-
-
-
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+ + +
+
    +
  • +
    +
    + + profile_pic
    -
    -
-
- - -
-
    -
  • -
    -
    - - profile_pic -
    -
    -
    - title -
    - - - -
    -
    -
    +
    +
    + title
    + + + +
    +
    +
    +
    +
  • +
+
+ + +
+
- - -
- -
- + page number + +
  • + + + +
  • + + +
    + -
    +
    \ No newline at end of file -- Gitee From dfbe7cce56933e6c9ef6a3a71890e8d0ecc69873 Mon Sep 17 00:00:00 2001 From: ab <672943942@qq.com> Date: Tue, 23 Apr 2019 22:43:20 +0800 Subject: [PATCH 03/13] =?UTF-8?q?=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fstack/service/impl/StorageServiceImpl.java | 7 +++++-- src/main/resources/application.properties | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/fstack/service/impl/StorageServiceImpl.java b/src/main/java/com/fstack/service/impl/StorageServiceImpl.java index ff15111..ae169d8 100644 --- a/src/main/java/com/fstack/service/impl/StorageServiceImpl.java +++ b/src/main/java/com/fstack/service/impl/StorageServiceImpl.java @@ -12,6 +12,7 @@ import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; import org.springframework.web.multipart.MultipartFile; +import java.io.File; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -44,14 +45,16 @@ public class StorageServiceImpl implements StorageService { } String filename = StringUtils.cleanPath(file.getOriginalFilename()); try { + File file1 = new File("/"); + String absolutePath = file1.getAbsolutePath(); String path = username + "/" + filename; - Path avatarLocation = Paths.get(this.staticResourceLocation + "/" + path); + Path avatarLocation = Paths.get(absolutePath + this.staticResourceLocation + "/" + path); Files.createDirectories(avatarLocation); Files.copy(file.getInputStream(), avatarLocation, StandardCopyOption.REPLACE_EXISTING); logger.info("Saved file to >> " + avatarLocation); // update user avatar location User user = this.userMapper.findByUsername(username); - user.setAvatarLocation(path); + user.setAvatarLocation(avatarLocation.toAbsolutePath().toString()); return user; } catch (Exception e) { throw new StorageException("Failed to store file " + filename, e); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 8ffdf2a..3cc53ef 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -37,7 +37,7 @@ pagehelper.params=count=countSql # ============================== # avatar location, must end with / # ============================== -resource.staticResourceLocation=D:/avatar/ +resource.staticResourceLocation=avatar/ spring.output.ansi.enabled=always logging.config=classpath:logback.xml \ No newline at end of file -- Gitee From bbbc11d81c2b8750e45f7f9ee5d0a6f2a96b85b2 Mon Sep 17 00:00:00 2001 From: ab <672943942@qq.com> Date: Tue, 23 Apr 2019 22:47:11 +0800 Subject: [PATCH 04/13] =?UTF-8?q?=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fstack/service/impl/StorageServiceImpl.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/fstack/service/impl/StorageServiceImpl.java b/src/main/java/com/fstack/service/impl/StorageServiceImpl.java index ae169d8..ab5318b 100644 --- a/src/main/java/com/fstack/service/impl/StorageServiceImpl.java +++ b/src/main/java/com/fstack/service/impl/StorageServiceImpl.java @@ -47,10 +47,10 @@ public class StorageServiceImpl implements StorageService { try { File file1 = new File("/"); String absolutePath = file1.getAbsolutePath(); - String path = username + "/" + filename; - Path avatarLocation = Paths.get(absolutePath + this.staticResourceLocation + "/" + path); + Path avatarLocation = Paths.get(absolutePath + this.staticResourceLocation + "/" + username); Files.createDirectories(avatarLocation); - Files.copy(file.getInputStream(), avatarLocation, StandardCopyOption.REPLACE_EXISTING); + Path resolve = avatarLocation.resolve(filename); + Files.copy(file.getInputStream(), resolve, StandardCopyOption.REPLACE_EXISTING); logger.info("Saved file to >> " + avatarLocation); // update user avatar location User user = this.userMapper.findByUsername(username); -- Gitee From 2cc1796c1665e90b2e247afa6cd76c0262d49c22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8D=8E?= <672943942@qq.com> Date: Wed, 24 Apr 2019 08:21:23 +0800 Subject: [PATCH 05/13] =?UTF-8?q?=E8=B7=AF=E5=BE=84=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/StorageServiceImpl.java | 13 ++++++------ src/main/java/com/fstack/util/CommonUtil.java | 21 +++++++++++++++++++ src/main/resources/application.properties | 2 +- 3 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 src/main/java/com/fstack/util/CommonUtil.java diff --git a/src/main/java/com/fstack/service/impl/StorageServiceImpl.java b/src/main/java/com/fstack/service/impl/StorageServiceImpl.java index ab5318b..907dc31 100644 --- a/src/main/java/com/fstack/service/impl/StorageServiceImpl.java +++ b/src/main/java/com/fstack/service/impl/StorageServiceImpl.java @@ -4,6 +4,7 @@ import com.fstack.exception.StorageException; import com.fstack.persistence.dao.UserMapper; import com.fstack.persistence.model.User; import com.fstack.service.StorageService; +import com.fstack.util.CommonUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -12,7 +13,6 @@ import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; import org.springframework.web.multipart.MultipartFile; -import java.io.File; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -45,16 +45,17 @@ public class StorageServiceImpl implements StorageService { } String filename = StringUtils.cleanPath(file.getOriginalFilename()); try { - File file1 = new File("/"); - String absolutePath = file1.getAbsolutePath(); - Path avatarLocation = Paths.get(absolutePath + this.staticResourceLocation + "/" + username); - Files.createDirectories(avatarLocation); + String path = this.staticResourceLocation + username; + Path avatarLocation = Paths.get(CommonUtil.getRootPath() + path); + if (!Files.exists(avatarLocation)){ + Files.createDirectories(avatarLocation); + } Path resolve = avatarLocation.resolve(filename); Files.copy(file.getInputStream(), resolve, StandardCopyOption.REPLACE_EXISTING); logger.info("Saved file to >> " + avatarLocation); // update user avatar location User user = this.userMapper.findByUsername(username); - user.setAvatarLocation(avatarLocation.toAbsolutePath().toString()); + user.setAvatarLocation(path); return user; } catch (Exception e) { throw new StorageException("Failed to store file " + filename, e); diff --git a/src/main/java/com/fstack/util/CommonUtil.java b/src/main/java/com/fstack/util/CommonUtil.java new file mode 100644 index 0000000..71cfffb --- /dev/null +++ b/src/main/java/com/fstack/util/CommonUtil.java @@ -0,0 +1,21 @@ +package com.fstack.util; + +import java.io.File; + +/** + * @author wongH + * @date 2019/4/24 8:08 + * @Version 1.0 + */ +public class CommonUtil { + + + public static String getRootPath() { + File file = new File("/"); + return file.getAbsolutePath(); + } + + public static String getProjectPath() { + return System.getProperty("user.dir"); + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 3cc53ef..9ef7254 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,5 +1,5 @@ server.port=8080 -spring.profiles.active=pro +spring.profiles.active=dev server.servlet.context-path= / spring.aop.proxy-target-class=true -- Gitee From ffeb45d692fb0c87fa8256ab179871b751b44d6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8D=8E?= <672943942@qq.com> Date: Wed, 24 Apr 2019 08:33:30 +0800 Subject: [PATCH 06/13] =?UTF-8?q?=E8=B7=AF=E5=BE=84=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/fstack/config/StaticResourceConfig.java | 3 ++- src/main/java/com/fstack/service/impl/StorageServiceImpl.java | 4 ++-- src/main/java/com/fstack/util/CommonUtil.java | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/fstack/config/StaticResourceConfig.java b/src/main/java/com/fstack/config/StaticResourceConfig.java index 3f9d205..48f5366 100644 --- a/src/main/java/com/fstack/config/StaticResourceConfig.java +++ b/src/main/java/com/fstack/config/StaticResourceConfig.java @@ -1,5 +1,6 @@ package com.fstack.config; +import com.fstack.util.CommonUtil; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.CorsRegistry; @@ -18,7 +19,7 @@ public class StaticResourceConfig implements WebMvcConfigurer { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/avatar/**") - .addResourceLocations("file:" + staticResourceLocation); + .addResourceLocations("file:" + CommonUtil.getRootPath() + staticResourceLocation); } @Override diff --git a/src/main/java/com/fstack/service/impl/StorageServiceImpl.java b/src/main/java/com/fstack/service/impl/StorageServiceImpl.java index 907dc31..ecf1499 100644 --- a/src/main/java/com/fstack/service/impl/StorageServiceImpl.java +++ b/src/main/java/com/fstack/service/impl/StorageServiceImpl.java @@ -52,10 +52,10 @@ public class StorageServiceImpl implements StorageService { } Path resolve = avatarLocation.resolve(filename); Files.copy(file.getInputStream(), resolve, StandardCopyOption.REPLACE_EXISTING); - logger.info("Saved file to >> " + avatarLocation); + logger.info("Saved file to >> " + resolve); // update user avatar location User user = this.userMapper.findByUsername(username); - user.setAvatarLocation(path); + user.setAvatarLocation(resolve.toAbsolutePath().toString()); return user; } catch (Exception e) { throw new StorageException("Failed to store file " + filename, e); diff --git a/src/main/java/com/fstack/util/CommonUtil.java b/src/main/java/com/fstack/util/CommonUtil.java index 71cfffb..22712fc 100644 --- a/src/main/java/com/fstack/util/CommonUtil.java +++ b/src/main/java/com/fstack/util/CommonUtil.java @@ -12,7 +12,8 @@ public class CommonUtil { public static String getRootPath() { File file = new File("/"); - return file.getAbsolutePath(); + String path = file.getAbsolutePath().replaceAll("\\\\", "/"); + return path; } public static String getProjectPath() { -- Gitee From 72029982574aa870f96ae6d5e43123288c51d465 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8D=8E?= <672943942@qq.com> Date: Wed, 24 Apr 2019 08:37:07 +0800 Subject: [PATCH 07/13] =?UTF-8?q?=E8=B7=AF=E5=BE=84=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/fstack/service/impl/StorageServiceImpl.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/fstack/service/impl/StorageServiceImpl.java b/src/main/java/com/fstack/service/impl/StorageServiceImpl.java index ecf1499..cf4f439 100644 --- a/src/main/java/com/fstack/service/impl/StorageServiceImpl.java +++ b/src/main/java/com/fstack/service/impl/StorageServiceImpl.java @@ -55,7 +55,8 @@ public class StorageServiceImpl implements StorageService { logger.info("Saved file to >> " + resolve); // update user avatar location User user = this.userMapper.findByUsername(username); - user.setAvatarLocation(resolve.toAbsolutePath().toString()); + String avatar = path + "/" + filename; + user.setAvatarLocation(avatar); return user; } catch (Exception e) { throw new StorageException("Failed to store file " + filename, e); -- Gitee From bb72a8957cc9c5453aa36cf683ec38a07cc25964 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8D=8E?= <672943942@qq.com> Date: Wed, 24 Apr 2019 08:40:15 +0800 Subject: [PATCH 08/13] =?UTF-8?q?=E8=B7=AF=E5=BE=84=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/templates/forum/user-settings.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/resources/templates/forum/user-settings.html b/src/main/resources/templates/forum/user-settings.html index 2eedb23..ff6b8b4 100644 --- a/src/main/resources/templates/forum/user-settings.html +++ b/src/main/resources/templates/forum/user-settings.html @@ -62,9 +62,9 @@ $(function() { - - - + + +
    当前头像:profile_fileprofile_fileprofile_fileprofile_fileprofile_fileprofile_file
    -- Gitee From 2c80c7140dbc38247be0ca4ca0fa8a387f4d66fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8D=8E?= <672943942@qq.com> Date: Wed, 24 Apr 2019 08:45:44 +0800 Subject: [PATCH 09/13] =?UTF-8?q?=E8=B7=AF=E5=BE=84=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/templates/forum/post.html | 2 +- src/main/resources/templates/forum/user-profile.html | 2 +- src/main/resources/templates/fragments/comments.html | 2 +- src/main/resources/templates/fragments/posts-list.html | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/resources/templates/forum/post.html b/src/main/resources/templates/forum/post.html index 4812780..3a917b8 100644 --- a/src/main/resources/templates/forum/post.html +++ b/src/main/resources/templates/forum/post.html @@ -18,7 +18,7 @@
    diff --git a/src/main/resources/templates/forum/user-profile.html b/src/main/resources/templates/forum/user-profile.html index 4c62cd8..1477a11 100644 --- a/src/main/resources/templates/forum/user-profile.html +++ b/src/main/resources/templates/forum/user-profile.html @@ -12,7 +12,7 @@
    profile_pic + th:src="@{'../'+${user.avatarLocation}}">
    diff --git a/src/main/resources/templates/fragments/comments.html b/src/main/resources/templates/fragments/comments.html index b472fc5..26e191d 100644 --- a/src/main/resources/templates/fragments/comments.html +++ b/src/main/resources/templates/fragments/comments.html @@ -10,7 +10,7 @@
    diff --git a/src/main/resources/templates/fragments/posts-list.html b/src/main/resources/templates/fragments/posts-list.html index 42daa54..a60edb9 100644 --- a/src/main/resources/templates/fragments/posts-list.html +++ b/src/main/resources/templates/fragments/posts-list.html @@ -23,7 +23,7 @@
    -- Gitee From e661489e90cf6915abab425db0d7e1511bd616e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8D=8E?= <672943942@qq.com> Date: Wed, 24 Apr 2019 09:11:03 +0800 Subject: [PATCH 10/13] pro --- src/main/resources/application.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 9ef7254..3cc53ef 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,5 +1,5 @@ server.port=8080 -spring.profiles.active=dev +spring.profiles.active=pro server.servlet.context-path= / spring.aop.proxy-target-class=true -- Gitee From 7dfd8c69053019dca9d56d5038ac7e5ef14d2056 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8D=8E?= <672943942@qq.com> Date: Wed, 24 Apr 2019 09:13:28 +0800 Subject: [PATCH 11/13] exception --- src/main/java/com/fstack/common/ApiResponse.java | 4 ++-- src/main/java/com/fstack/config/GlobalExceptionHandler.java | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/fstack/common/ApiResponse.java b/src/main/java/com/fstack/common/ApiResponse.java index 57960ea..59fe568 100644 --- a/src/main/java/com/fstack/common/ApiResponse.java +++ b/src/main/java/com/fstack/common/ApiResponse.java @@ -57,7 +57,7 @@ public class ApiResponse { return new ApiResponse(false, 6,"对不起,您没有没有权限"); } - public static ApiResponse toException() { - return new ApiResponse(false, 404, "exception"); + public static ApiResponse toException(String msg) { + return new ApiResponse(false, 404, msg); } } diff --git a/src/main/java/com/fstack/config/GlobalExceptionHandler.java b/src/main/java/com/fstack/config/GlobalExceptionHandler.java index 36d3188..d801b7c 100644 --- a/src/main/java/com/fstack/config/GlobalExceptionHandler.java +++ b/src/main/java/com/fstack/config/GlobalExceptionHandler.java @@ -1,5 +1,6 @@ package com.fstack.config; +import com.fstack.common.ApiResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.web.bind.annotation.ControllerAdvice; @@ -25,7 +26,7 @@ public class GlobalExceptionHandler { * @param response */ @ExceptionHandler(value = Exception.class) - private void handle(Exception ex, HttpServletRequest request, HttpServletResponse response) { + public ApiResponse handle(Exception ex, HttpServletRequest request, HttpServletResponse response) { logger.error("***** GlobalException Start *****"); logger.error("Exception:{}", ex.toString()); logger.error("Message:{}", ex.getMessage()); @@ -42,6 +43,7 @@ public class GlobalExceptionHandler { } logger.error("***** GlobalException End *****"); + return ApiResponse.toException(ex.getMessage()); } -- Gitee From 6cffc6481b141e1fcb202381ea5d31f4f5d77c8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8D=8E?= <672943942@qq.com> Date: Wed, 24 Apr 2019 09:17:08 +0800 Subject: [PATCH 12/13] exception --- .../java/com/fstack/config/GlobalExceptionHandler.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/main/java/com/fstack/config/GlobalExceptionHandler.java b/src/main/java/com/fstack/config/GlobalExceptionHandler.java index d801b7c..7d0850e 100644 --- a/src/main/java/com/fstack/config/GlobalExceptionHandler.java +++ b/src/main/java/com/fstack/config/GlobalExceptionHandler.java @@ -28,8 +28,6 @@ public class GlobalExceptionHandler { @ExceptionHandler(value = Exception.class) public ApiResponse handle(Exception ex, HttpServletRequest request, HttpServletResponse response) { logger.error("***** GlobalException Start *****"); - logger.error("Exception:{}", ex.toString()); - logger.error("Message:{}", ex.getMessage()); logger.error("Request Url:{}", request.getRequestURL()); Enumeration enumeration = request.getParameterNames(); logger.error("Parameters:"); @@ -37,11 +35,7 @@ public class GlobalExceptionHandler { String name = enumeration.nextElement().toString(); logger.error("[{}]:[{}]", name, request.getParameter(name)); } - StackTraceElement[] error = ex.getStackTrace(); - for (StackTraceElement stackTraceElement : error) { - logger.error("StackTrace:{}", stackTraceElement.toString()); - } - + ex.printStackTrace(); logger.error("***** GlobalException End *****"); return ApiResponse.toException(ex.getMessage()); } -- Gitee From 5eefdb9b910cdb3bbf8f7fad67c300056a8c1991 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8D=8E?= <672943942@qq.com> Date: Wed, 24 Apr 2019 09:23:55 +0800 Subject: [PATCH 13/13] "" --- src/main/resources/application-dev.properties | 1 - src/main/resources/application-pro.properties | 1 - 2 files changed, 2 deletions(-) diff --git a/src/main/resources/application-dev.properties b/src/main/resources/application-dev.properties index 720dea0..5c51037 100644 --- a/src/main/resources/application-dev.properties +++ b/src/main/resources/application-dev.properties @@ -28,7 +28,6 @@ spring.redis.lettuce.pool.min-idle=5 spring.redis.lettuce.pool.max-active=20 spring.redis.lettuce.pool.max-wait=-1ms - # ============================== # SMTP Email # ============================== diff --git a/src/main/resources/application-pro.properties b/src/main/resources/application-pro.properties index 761aad8..4e83710 100644 --- a/src/main/resources/application-pro.properties +++ b/src/main/resources/application-pro.properties @@ -28,7 +28,6 @@ spring.redis.lettuce.pool.min-idle=5 spring.redis.lettuce.pool.max-active=20 spring.redis.lettuce.pool.max-wait=-1ms - # ============================== # SMTP Email # ============================== -- Gitee