From d77ce5b4468616e2476a9e5cea5fea3ad86b6226 Mon Sep 17 00:00:00 2001 From: xiongxiaoyang <1179705413@qq.com> Date: Sat, 15 Mar 2025 23:35:47 +0800 Subject: [PATCH] =?UTF-8?q?build:=20Spring=20Boot=20=E5=8D=87=E7=BA=A7?= =?UTF-8?q?=E5=88=B0=203.4.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- novel-common/pom.xml | 16 +---- .../java2nb/novel/core/utils/FileUtil.java | 2 +- .../com/java2nb/novel/core/utils/IpUtil.java | 2 +- .../novel/core/utils/RestTemplates.java | 38 +++++------ .../java2nb/novel/core/utils/SpringUtil.java | 37 +++++++++++ .../java/com/java2nb/novel/entity/User.java | 2 +- .../main/resources/application-common-dev.yml | 21 +++--- .../resources/application-common-prod.yml | 4 +- .../core/config/SecurityConfiguration.java | 64 ++++++++++--------- .../novel/core/listener/StarterListener.java | 2 +- .../novel/service/impl/CrawlServiceImpl.java | 2 +- .../src/main/resources/application-dev.yml | 4 +- .../src/main/resources/application-prod.yml | 4 +- .../src/main/resources/application.yml | 4 +- .../src/main/resources/logback-boot.xml | 37 +++++------ .../novel/controller/AuthorController.java | 4 +- .../novel/controller/BaseController.java | 3 +- .../novel/controller/BookController.java | 2 +- .../novel/controller/FileController.java | 4 +- .../novel/controller/PayController.java | 4 +- .../novel/controller/UserController.java | 2 +- .../novel/controller/page/PageController.java | 2 +- .../novel/core/config/FilterConfig.java | 2 +- .../novel/core/config/WebMvcConfig.java | 4 +- .../novel/core/filter/NovelFilter.java | 13 ++-- .../java2nb/novel/core/filter/XssFilter.java | 4 +- .../novel/core/listener/StarterListener.java | 2 +- .../java2nb/novel/core/utils/BrowserUtil.java | 3 +- .../java2nb/novel/core/utils/CookieUtil.java | 8 +-- .../novel/core/utils/ThreadLocalUtil.java | 1 - .../wrapper/XssHttpServletRequestWrapper.java | 8 +-- .../novel/service/impl/BookServiceImpl.java | 28 +++----- .../com/java2nb/novel/vo/BookCommentVO.java | 1 - .../src/main/resources/application-dev.yml | 4 +- .../src/main/resources/application-prod.yml | 4 +- .../src/main/resources/logback-boot.xml | 39 ++++++----- .../mybatis/mapping/BookCommentMapper.xml | 2 +- .../resources/mybatis/mapping/BookMapper.xml | 3 + pom.xml | 7 +- 39 files changed, 201 insertions(+), 192 deletions(-) create mode 100644 novel-common/src/main/java/com/java2nb/novel/core/utils/SpringUtil.java diff --git a/novel-common/pom.xml b/novel-common/pom.xml index 32bb22d..462c5e9 100644 --- a/novel-common/pom.xml +++ b/novel-common/pom.xml @@ -71,11 +71,6 @@ pagehelper-spring-boot-starter ${pagehelper.version} - - com.cuisongliu - orderbyhelper-spring-boot-starter - ${orderbyhelper.version} - org.apache.commons @@ -84,15 +79,8 @@ - org.apache.httpcomponents - httpclient - 4.5.14 - - - commons-logging - commons-logging - - + org.apache.httpcomponents.client5 + httpclient5 diff --git a/novel-common/src/main/java/com/java2nb/novel/core/utils/FileUtil.java b/novel-common/src/main/java/com/java2nb/novel/core/utils/FileUtil.java index cbe1b06..f64e4eb 100644 --- a/novel-common/src/main/java/com/java2nb/novel/core/utils/FileUtil.java +++ b/novel-common/src/main/java/com/java2nb/novel/core/utils/FileUtil.java @@ -5,7 +5,7 @@ import lombok.SneakyThrows; import lombok.experimental.UtilityClass; import lombok.extern.slf4j.Slf4j; import org.apache.commons.codec.Charsets; -import org.apache.http.client.utils.DateUtils; +import org.apache.hc.client5.http.utils.DateUtils; import org.springframework.core.io.Resource; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; diff --git a/novel-common/src/main/java/com/java2nb/novel/core/utils/IpUtil.java b/novel-common/src/main/java/com/java2nb/novel/core/utils/IpUtil.java index c7f92d2..754e93d 100644 --- a/novel-common/src/main/java/com/java2nb/novel/core/utils/IpUtil.java +++ b/novel-common/src/main/java/com/java2nb/novel/core/utils/IpUtil.java @@ -1,6 +1,6 @@ package com.java2nb.novel.core.utils; -import javax.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletRequest; public class IpUtil { diff --git a/novel-common/src/main/java/com/java2nb/novel/core/utils/RestTemplates.java b/novel-common/src/main/java/com/java2nb/novel/core/utils/RestTemplates.java index 58bf452..b7de405 100644 --- a/novel-common/src/main/java/com/java2nb/novel/core/utils/RestTemplates.java +++ b/novel-common/src/main/java/com/java2nb/novel/core/utils/RestTemplates.java @@ -3,21 +3,21 @@ package com.java2nb.novel.core.utils; import com.java2nb.novel.core.config.HttpProxyProperties; import lombok.SneakyThrows; import org.apache.commons.lang3.StringUtils; -import org.apache.http.HttpHost; -import org.apache.http.auth.AuthScope; -import org.apache.http.auth.UsernamePasswordCredentials; -import org.apache.http.client.CredentialsProvider; -import org.apache.http.config.Registry; -import org.apache.http.config.RegistryBuilder; -import org.apache.http.conn.socket.ConnectionSocketFactory; -import org.apache.http.conn.socket.PlainConnectionSocketFactory; -import org.apache.http.conn.ssl.SSLConnectionSocketFactory; -import org.apache.http.conn.ssl.TrustStrategy; -import org.apache.http.impl.client.BasicCredentialsProvider; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; +import org.apache.hc.client5.http.auth.AuthScope; +import org.apache.hc.client5.http.auth.UsernamePasswordCredentials; +import org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider; +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; +import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; +import org.apache.hc.client5.http.impl.classic.HttpClients; +import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager; +import org.apache.hc.client5.http.socket.ConnectionSocketFactory; +import org.apache.hc.client5.http.socket.PlainConnectionSocketFactory; +import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory; +import org.apache.hc.core5.http.HttpHost; +import org.apache.hc.core5.http.config.Registry; +import org.apache.hc.core5.http.config.RegistryBuilder; +import org.apache.hc.core5.ssl.SSLContexts; +import org.apache.hc.core5.ssl.TrustStrategy; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.StringHttpMessageConverter; @@ -45,7 +45,7 @@ public class RestTemplates { TrustStrategy acceptingTrustStrategy = (X509Certificate[] chain, String authType) -> true; //忽略证书 - SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom() + SSLContext sslContext = SSLContexts.custom() .loadTrustMaterial(null, acceptingTrustStrategy) .build(); @@ -69,10 +69,10 @@ public class RestTemplates { if (StringUtils.isNotBlank(httpProxyProperties.getUsername()) && StringUtils.isNotBlank( httpProxyProperties.getPassword())) { // 创建CredentialsProvider实例并添加代理认证信息 - CredentialsProvider provider = new BasicCredentialsProvider(); + BasicCredentialsProvider provider = new BasicCredentialsProvider(); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials( - httpProxyProperties.getUsername(), httpProxyProperties.getPassword()); - provider.setCredentials(AuthScope.ANY, credentials); + httpProxyProperties.getUsername(), httpProxyProperties.getPassword().toCharArray()); + provider.setCredentials(new AuthScope(null, -1), credentials); clientBuilder.setDefaultCredentialsProvider(provider); } } diff --git a/novel-common/src/main/java/com/java2nb/novel/core/utils/SpringUtil.java b/novel-common/src/main/java/com/java2nb/novel/core/utils/SpringUtil.java new file mode 100644 index 0000000..5c7ea6d --- /dev/null +++ b/novel-common/src/main/java/com/java2nb/novel/core/utils/SpringUtil.java @@ -0,0 +1,37 @@ +package com.java2nb.novel.core.utils; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.stereotype.Component; + +@Component +public class SpringUtil implements ApplicationContextAware { + private static ApplicationContext applicationContext; + + public SpringUtil() { + } + + public void setApplicationContext(ApplicationContext applicationContext) { + if (SpringUtil.applicationContext == null) { + SpringUtil.applicationContext = applicationContext; + } + + } + + public static ApplicationContext getApplicationContext() { + return applicationContext; + } + + public static Object getBean(String name) { + return getApplicationContext().getBean(name); + } + + public static T getBean(Class clazz) { + return (T)getApplicationContext().getBean(clazz); + } + + public static T getBean(String name, Class clazz) { + return (T)getApplicationContext().getBean(name, clazz); + } +} + diff --git a/novel-common/src/main/java/com/java2nb/novel/entity/User.java b/novel-common/src/main/java/com/java2nb/novel/entity/User.java index a3a1d5a..7da42eb 100644 --- a/novel-common/src/main/java/com/java2nb/novel/entity/User.java +++ b/novel-common/src/main/java/com/java2nb/novel/entity/User.java @@ -2,9 +2,9 @@ package com.java2nb.novel.entity; import io.github.xxyopen.web.valid.AddGroup; import io.github.xxyopen.web.valid.UpdateGroup; +import jakarta.validation.constraints.*; import javax.annotation.Generated; -import javax.validation.constraints.*; import java.util.Date; public class User { diff --git a/novel-common/src/main/resources/application-common-dev.yml b/novel-common/src/main/resources/application-common-dev.yml index e44d19a..003144c 100644 --- a/novel-common/src/main/resources/application-common-dev.yml +++ b/novel-common/src/main/resources/application-common-dev.yml @@ -1,17 +1,18 @@ spring: - profiles: - include: [ common ] + config: + import: classpath:application-common.yml main: allow-bean-definition-overriding: true #Redis服务器IP - redis: - host: 127.0.0.1 - #Redis服务器连接端口 - port: 6379 - #Redis服务器连接密码 - password: test123456 - #连接超时时间(毫秒) - timeout: 10000 + data: + redis: + host: 127.0.0.1 + #Redis服务器连接端口 + port: 6379 + #Redis服务器连接密码 + password: test123456 + #连接超时时间(毫秒) + timeout: 10000 content: save: diff --git a/novel-common/src/main/resources/application-common-prod.yml b/novel-common/src/main/resources/application-common-prod.yml index 7a8d8b3..7c99121 100644 --- a/novel-common/src/main/resources/application-common-prod.yml +++ b/novel-common/src/main/resources/application-common-prod.yml @@ -1,6 +1,6 @@ spring: - profiles: - include: [ common ] + config: + import: classpath:application-common.yml main: allow-bean-definition-overriding: true #Redis服务器IP diff --git a/novel-crawl/src/main/java/com/java2nb/novel/core/config/SecurityConfiguration.java b/novel-crawl/src/main/java/com/java2nb/novel/core/config/SecurityConfiguration.java index ff35ebc..f684fe4 100644 --- a/novel-crawl/src/main/java/com/java2nb/novel/core/config/SecurityConfiguration.java +++ b/novel-crawl/src/main/java/com/java2nb/novel/core/config/SecurityConfiguration.java @@ -4,14 +4,15 @@ import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.Customizer; import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.builders.WebSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.core.userdetails.User; +import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.security.provisioning.InMemoryUserDetailsManager; +import org.springframework.security.web.SecurityFilterChain; /** * SpringSecurity配置 @@ -21,7 +22,7 @@ import org.springframework.security.crypto.password.PasswordEncoder; @Configuration @EnableWebSecurity @RequiredArgsConstructor -public class SecurityConfiguration extends WebSecurityConfigurerAdapter { +public class SecurityConfiguration { @Value("${admin.username}") private String username; @@ -29,39 +30,40 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { @Value("${admin.password}") private String password; - @Bean public PasswordEncoder passwordEncoder() { return new BCryptPasswordEncoder(); } - - @Override - public void configure(WebSecurity web) throws Exception { - super.configure(web); + @Bean + public InMemoryUserDetailsManager userDetailsService() { + UserDetails admin = User.builder() + .username(username) + .password(passwordEncoder().encode(password)) + .roles("ADMIN") + .build(); + return new InMemoryUserDetailsManager(admin); } - @Override - public void configure(AuthenticationManagerBuilder auth) throws Exception { + @Bean + public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { + http + .csrf(csrf -> csrf.disable()) // 禁用 CSRF + .authorizeHttpRequests(auth -> auth + .requestMatchers("/css/**", "/favicon.ico").permitAll() // 允许访问静态资源 + .anyRequest().hasRole("ADMIN") // 其他请求需要 ADMIN 角色 + ) + .formLogin(form -> form + .loginPage("/login.html") // 自定义登录页面 + .loginProcessingUrl("/login") // 登录处理 URL + .permitAll() + ) + .logout(logout -> logout + .logoutUrl("/logout") // 登出 URL + .logoutSuccessUrl("/") // 登出成功后跳转的页面 + ) + .httpBasic(Customizer.withDefaults()); // 启用 HTTP Basic 认证 - User.UserBuilder builder = User.builder().passwordEncoder(passwordEncoder()::encode); - auth.inMemoryAuthentication().withUser(builder.username(username).password(password).roles("ADMIN").build()); + return http.build(); } - - @Override - protected void configure(HttpSecurity http) throws Exception { - http.csrf().disable() - .authorizeRequests() - .antMatchers("/css/**").permitAll() - .antMatchers("/favicon.ico").permitAll() - .antMatchers("/**").hasRole("ADMIN") - .and().formLogin().loginPage("/login.html").loginProcessingUrl("/login").permitAll() - .and().logout() - .logoutUrl("/logout") - .logoutSuccessUrl("/") - .and().httpBasic(); - - } - - -} +} \ No newline at end of file diff --git a/novel-crawl/src/main/java/com/java2nb/novel/core/listener/StarterListener.java b/novel-crawl/src/main/java/com/java2nb/novel/core/listener/StarterListener.java index c15cdae..6d7f9cf 100644 --- a/novel-crawl/src/main/java/com/java2nb/novel/core/listener/StarterListener.java +++ b/novel-crawl/src/main/java/com/java2nb/novel/core/listener/StarterListener.java @@ -10,6 +10,7 @@ import com.java2nb.novel.entity.CrawlSource; import com.java2nb.novel.service.BookService; import com.java2nb.novel.service.CrawlService; import com.java2nb.novel.utils.Constants; +import jakarta.servlet.ServletContext; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.time.DateUtils; @@ -17,7 +18,6 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.web.servlet.ServletContextInitializer; import org.springframework.stereotype.Component; -import javax.servlet.ServletContext; import java.util.Date; import java.util.List; import java.util.Map; diff --git a/novel-crawl/src/main/java/com/java2nb/novel/service/impl/CrawlServiceImpl.java b/novel-crawl/src/main/java/com/java2nb/novel/service/impl/CrawlServiceImpl.java index 0e6f849..b3bc75b 100644 --- a/novel-crawl/src/main/java/com/java2nb/novel/service/impl/CrawlServiceImpl.java +++ b/novel-crawl/src/main/java/com/java2nb/novel/service/impl/CrawlServiceImpl.java @@ -7,6 +7,7 @@ import com.java2nb.novel.core.cache.CacheService; import com.java2nb.novel.core.crawl.CrawlParser; import com.java2nb.novel.core.crawl.RuleBean; import com.java2nb.novel.core.enums.ResponseStatus; +import com.java2nb.novel.core.utils.SpringUtil; import com.java2nb.novel.entity.Book; import com.java2nb.novel.entity.CrawlSingleTask; import com.java2nb.novel.entity.CrawlSource; @@ -25,7 +26,6 @@ import io.github.xxyopen.util.IdWorker; import io.github.xxyopen.util.ThreadUtil; import io.github.xxyopen.web.exception.BusinessException; import io.github.xxyopen.web.util.BeanUtil; -import io.github.xxyopen.web.util.SpringUtil; import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; diff --git a/novel-crawl/src/main/resources/application-dev.yml b/novel-crawl/src/main/resources/application-dev.yml index 4ea9fe8..f53bb81 100644 --- a/novel-crawl/src/main/resources/application-dev.yml +++ b/novel-crawl/src/main/resources/application-dev.yml @@ -1,3 +1,3 @@ spring: - profiles: - include: [common-dev] \ No newline at end of file + config: + import: classpath:application-common-dev.yml \ No newline at end of file diff --git a/novel-crawl/src/main/resources/application-prod.yml b/novel-crawl/src/main/resources/application-prod.yml index 54ce802..14d0afa 100644 --- a/novel-crawl/src/main/resources/application-prod.yml +++ b/novel-crawl/src/main/resources/application-prod.yml @@ -1,3 +1,3 @@ spring: - profiles: - include: [common-prod] \ No newline at end of file + config: + import: classpath:application-common-prod.yml \ No newline at end of file diff --git a/novel-crawl/src/main/resources/application.yml b/novel-crawl/src/main/resources/application.yml index 0979161..b4908fe 100644 --- a/novel-crawl/src/main/resources/application.yml +++ b/novel-crawl/src/main/resources/application.yml @@ -8,9 +8,7 @@ server: spring: profiles: active: dev - config: - use-legacy-processing: true - + #登录用户名密码 admin: username: admin diff --git a/novel-crawl/src/main/resources/logback-boot.xml b/novel-crawl/src/main/resources/logback-boot.xml index 05c7c83..2691bfd 100644 --- a/novel-crawl/src/main/resources/logback-boot.xml +++ b/novel-crawl/src/main/resources/logback-boot.xml @@ -12,9 +12,6 @@ - ${CONSOLE_LOG_PATTERN} UTF-8 @@ -22,43 +19,43 @@ - - + + - - logs/novel-crawl.log + + logs/novel-crawl.log - - + + - - logs/debug.%d.%i.log + + logs/debug.%d{yyyy-MM-dd}.%i.log 30 - - - 10MB - + + 10MB + + 1GB - - %d %p (%file:%line\)- %m%n - + %d %p (%file:%line\)- %m%n UTF-8 + + - + - + \ No newline at end of file diff --git a/novel-front/src/main/java/com/java2nb/novel/controller/AuthorController.java b/novel-front/src/main/java/com/java2nb/novel/controller/AuthorController.java index c89d02f..2b4912e 100644 --- a/novel-front/src/main/java/com/java2nb/novel/controller/AuthorController.java +++ b/novel-front/src/main/java/com/java2nb/novel/controller/AuthorController.java @@ -12,11 +12,11 @@ import com.java2nb.novel.entity.AuthorIncomeDetail; import com.java2nb.novel.entity.Book; import com.java2nb.novel.service.AuthorService; import com.java2nb.novel.service.BookService; +import jakarta.servlet.http.HttpServletRequest; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; -import javax.servlet.http.HttpServletRequest; import java.util.Date; /** @@ -54,7 +54,7 @@ public class AuthorController extends BaseController{ * 发布小说 * */ @PostMapping("addBook") - public RestResult addBook(@RequestParam("bookDesc") String bookDesc,Book book,HttpServletRequest request){ + public RestResult addBook(@RequestParam("bookDesc") String bookDesc, Book book, HttpServletRequest request){ Author author = checkAuthor(request); diff --git a/novel-front/src/main/java/com/java2nb/novel/controller/BaseController.java b/novel-front/src/main/java/com/java2nb/novel/controller/BaseController.java index 0df2607..3439135 100644 --- a/novel-front/src/main/java/com/java2nb/novel/controller/BaseController.java +++ b/novel-front/src/main/java/com/java2nb/novel/controller/BaseController.java @@ -3,11 +3,10 @@ package com.java2nb.novel.controller; import com.java2nb.novel.core.bean.UserDetails; import com.java2nb.novel.core.utils.CookieUtil; import com.java2nb.novel.core.utils.JwtTokenUtil; +import jakarta.servlet.http.HttpServletRequest; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServletRequest; /** * @author 11797 diff --git a/novel-front/src/main/java/com/java2nb/novel/controller/BookController.java b/novel-front/src/main/java/com/java2nb/novel/controller/BookController.java index 5581bb1..b5d1faf 100644 --- a/novel-front/src/main/java/com/java2nb/novel/controller/BookController.java +++ b/novel-front/src/main/java/com/java2nb/novel/controller/BookController.java @@ -15,11 +15,11 @@ import com.java2nb.novel.vo.BookVO; import io.github.xxyopen.model.page.PageBean; import io.github.xxyopen.model.page.builder.pagehelper.PageBuilder; import io.github.xxyopen.model.resp.RestResult; +import jakarta.servlet.http.HttpServletRequest; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; -import javax.servlet.http.HttpServletRequest; import java.util.HashMap; import java.util.List; import java.util.Map; diff --git a/novel-front/src/main/java/com/java2nb/novel/controller/FileController.java b/novel-front/src/main/java/com/java2nb/novel/controller/FileController.java index e696599..7f6f39c 100644 --- a/novel-front/src/main/java/com/java2nb/novel/controller/FileController.java +++ b/novel-front/src/main/java/com/java2nb/novel/controller/FileController.java @@ -10,6 +10,8 @@ import com.java2nb.novel.core.utils.RandomValidateCodeUtil; import io.github.xxyopen.model.resp.RestResult; import io.github.xxyopen.util.UUIDUtil; import io.github.xxyopen.web.exception.BusinessException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; @@ -19,8 +21,6 @@ import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import java.io.File; import java.util.Date; diff --git a/novel-front/src/main/java/com/java2nb/novel/controller/PayController.java b/novel-front/src/main/java/com/java2nb/novel/controller/PayController.java index f5bb878..96d2e0f 100644 --- a/novel-front/src/main/java/com/java2nb/novel/controller/PayController.java +++ b/novel-front/src/main/java/com/java2nb/novel/controller/PayController.java @@ -12,6 +12,8 @@ import com.java2nb.novel.core.bean.UserDetails; import com.java2nb.novel.core.config.AlipayProperties; import com.java2nb.novel.core.utils.ThreadLocalUtil; import com.java2nb.novel.service.OrderService; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; @@ -19,8 +21,6 @@ import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import java.io.PrintWriter; import java.nio.charset.StandardCharsets; import java.util.HashMap; diff --git a/novel-front/src/main/java/com/java2nb/novel/controller/UserController.java b/novel-front/src/main/java/com/java2nb/novel/controller/UserController.java index 5357d9f..958db22 100644 --- a/novel-front/src/main/java/com/java2nb/novel/controller/UserController.java +++ b/novel-front/src/main/java/com/java2nb/novel/controller/UserController.java @@ -13,13 +13,13 @@ import com.java2nb.novel.service.UserService; import io.github.xxyopen.model.resp.RestResult; import io.github.xxyopen.web.valid.AddGroup; import io.github.xxyopen.web.valid.UpdateGroup; +import jakarta.servlet.http.HttpServletRequest; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; -import javax.servlet.http.HttpServletRequest; import java.util.HashMap; import java.util.Map; diff --git a/novel-front/src/main/java/com/java2nb/novel/controller/page/PageController.java b/novel-front/src/main/java/com/java2nb/novel/controller/page/PageController.java index bf4c69f..765b07e 100644 --- a/novel-front/src/main/java/com/java2nb/novel/controller/page/PageController.java +++ b/novel-front/src/main/java/com/java2nb/novel/controller/page/PageController.java @@ -8,6 +8,7 @@ import com.java2nb.novel.service.*; import com.java2nb.novel.vo.BookCommentVO; import com.java2nb.novel.vo.BookSettingVO; import io.github.xxyopen.model.page.PageBean; +import jakarta.servlet.http.HttpServletRequest; import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; @@ -17,7 +18,6 @@ import org.springframework.ui.Model; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; -import javax.servlet.http.HttpServletRequest; import java.util.List; import java.util.Map; import java.util.concurrent.CompletableFuture; diff --git a/novel-front/src/main/java/com/java2nb/novel/core/config/FilterConfig.java b/novel-front/src/main/java/com/java2nb/novel/core/config/FilterConfig.java index 7229594..9d73865 100644 --- a/novel-front/src/main/java/com/java2nb/novel/core/config/FilterConfig.java +++ b/novel-front/src/main/java/com/java2nb/novel/core/config/FilterConfig.java @@ -2,13 +2,13 @@ package com.java2nb.novel.core.config; import com.java2nb.novel.core.filter.NovelFilter; import com.java2nb.novel.core.filter.XssFilter; +import jakarta.servlet.DispatcherType; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import javax.servlet.DispatcherType; import java.util.HashMap; import java.util.Map; diff --git a/novel-front/src/main/java/com/java2nb/novel/core/config/WebMvcConfig.java b/novel-front/src/main/java/com/java2nb/novel/core/config/WebMvcConfig.java index c535b6d..2d36783 100644 --- a/novel-front/src/main/java/com/java2nb/novel/core/config/WebMvcConfig.java +++ b/novel-front/src/main/java/com/java2nb/novel/core/config/WebMvcConfig.java @@ -3,13 +3,13 @@ package com.java2nb.novel.core.config; import com.java2nb.novel.core.converter.DateConverter; import org.springframework.context.annotation.Configuration; import org.springframework.format.FormatterRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; /** * @author xiongxiaoyang */ @Configuration -public class WebMvcConfig extends WebMvcConfigurerAdapter { +public class WebMvcConfig implements WebMvcConfigurer { @Override public void addFormatters(FormatterRegistry registry) { registry.addConverter(new DateConverter()); diff --git a/novel-front/src/main/java/com/java2nb/novel/core/filter/NovelFilter.java b/novel-front/src/main/java/com/java2nb/novel/core/filter/NovelFilter.java index 88e3e6d..7de65dd 100644 --- a/novel-front/src/main/java/com/java2nb/novel/core/filter/NovelFilter.java +++ b/novel-front/src/main/java/com/java2nb/novel/core/filter/NovelFilter.java @@ -4,13 +4,14 @@ import com.java2nb.novel.core.cache.CacheKey; import com.java2nb.novel.core.cache.CacheService; import com.java2nb.novel.core.utils.*; import io.github.xxyopen.util.UUIDUtil; -import io.github.xxyopen.web.util.SpringUtil; +import jakarta.servlet.*; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; -import javax.servlet.*; -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.*; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; /** * 项目核心过滤器 diff --git a/novel-front/src/main/java/com/java2nb/novel/core/filter/XssFilter.java b/novel-front/src/main/java/com/java2nb/novel/core/filter/XssFilter.java index 898ccb9..f285a48 100644 --- a/novel-front/src/main/java/com/java2nb/novel/core/filter/XssFilter.java +++ b/novel-front/src/main/java/com/java2nb/novel/core/filter/XssFilter.java @@ -1,11 +1,11 @@ package com.java2nb.novel.core.filter; import com.java2nb.novel.core.wrapper.XssHttpServletRequestWrapper; +import jakarta.servlet.*; +import jakarta.servlet.http.HttpServletRequest; import lombok.SneakyThrows; import org.apache.commons.lang3.StringUtils; -import javax.servlet.*; -import javax.servlet.http.HttpServletRequest; import java.util.ArrayList; import java.util.Arrays; import java.util.List; diff --git a/novel-front/src/main/java/com/java2nb/novel/core/listener/StarterListener.java b/novel-front/src/main/java/com/java2nb/novel/core/listener/StarterListener.java index 96a6b48..2af02bd 100644 --- a/novel-front/src/main/java/com/java2nb/novel/core/listener/StarterListener.java +++ b/novel-front/src/main/java/com/java2nb/novel/core/listener/StarterListener.java @@ -3,12 +3,12 @@ package com.java2nb.novel.core.listener; import com.java2nb.novel.core.config.WebsiteProperties; import com.java2nb.novel.entity.WebsiteInfo; import com.java2nb.novel.mapper.WebsiteInfoMapper; +import jakarta.servlet.ServletContext; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.web.servlet.ServletContextInitializer; import org.springframework.stereotype.Component; -import javax.servlet.ServletContext; /** * 启动监听器 diff --git a/novel-front/src/main/java/com/java2nb/novel/core/utils/BrowserUtil.java b/novel-front/src/main/java/com/java2nb/novel/core/utils/BrowserUtil.java index 29915f4..be2bddb 100644 --- a/novel-front/src/main/java/com/java2nb/novel/core/utils/BrowserUtil.java +++ b/novel-front/src/main/java/com/java2nb/novel/core/utils/BrowserUtil.java @@ -1,6 +1,7 @@ package com.java2nb.novel.core.utils; -import javax.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletRequest; + import java.util.regex.Pattern; public class BrowserUtil { diff --git a/novel-front/src/main/java/com/java2nb/novel/core/utils/CookieUtil.java b/novel-front/src/main/java/com/java2nb/novel/core/utils/CookieUtil.java index 7fd4f0d..06b0954 100644 --- a/novel-front/src/main/java/com/java2nb/novel/core/utils/CookieUtil.java +++ b/novel-front/src/main/java/com/java2nb/novel/core/utils/CookieUtil.java @@ -1,15 +1,15 @@ package com.java2nb.novel.core.utils; -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.Cookie; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; /** * @author Administrator */ public class CookieUtil { - public static String getCookie(HttpServletRequest request,String key){ + public static String getCookie(HttpServletRequest request, String key){ Cookie[] cookies = request.getCookies(); if(cookies != null) { for (Cookie cookie : cookies) { diff --git a/novel-front/src/main/java/com/java2nb/novel/core/utils/ThreadLocalUtil.java b/novel-front/src/main/java/com/java2nb/novel/core/utils/ThreadLocalUtil.java index 0cc9da8..b830c6f 100644 --- a/novel-front/src/main/java/com/java2nb/novel/core/utils/ThreadLocalUtil.java +++ b/novel-front/src/main/java/com/java2nb/novel/core/utils/ThreadLocalUtil.java @@ -2,7 +2,6 @@ package com.java2nb.novel.core.utils; import com.java2nb.novel.core.cache.CacheKey; import com.java2nb.novel.core.cache.CacheService; -import io.github.xxyopen.web.util.SpringUtil; /** * 模板操作工具类 diff --git a/novel-front/src/main/java/com/java2nb/novel/core/wrapper/XssHttpServletRequestWrapper.java b/novel-front/src/main/java/com/java2nb/novel/core/wrapper/XssHttpServletRequestWrapper.java index c99e459..6c7b102 100644 --- a/novel-front/src/main/java/com/java2nb/novel/core/wrapper/XssHttpServletRequestWrapper.java +++ b/novel-front/src/main/java/com/java2nb/novel/core/wrapper/XssHttpServletRequestWrapper.java @@ -1,11 +1,7 @@ package com.java2nb.novel.core.wrapper; -import org.apache.commons.lang3.StringUtils; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletRequestWrapper; -import java.util.Arrays; -import java.util.List; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletRequestWrapper; /** * XSS过滤处理 diff --git a/novel-front/src/main/java/com/java2nb/novel/service/impl/BookServiceImpl.java b/novel-front/src/main/java/com/java2nb/novel/service/impl/BookServiceImpl.java index b625a2d..194908d 100644 --- a/novel-front/src/main/java/com/java2nb/novel/service/impl/BookServiceImpl.java +++ b/novel-front/src/main/java/com/java2nb/novel/service/impl/BookServiceImpl.java @@ -29,19 +29,16 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.mybatis.dynamic.sql.SortSpecification; import org.mybatis.dynamic.sql.render.RenderingStrategies; +import org.mybatis.dynamic.sql.select.QueryExpressionDSL; import org.mybatis.dynamic.sql.select.render.SelectStatementProvider; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import tk.mybatis.orderbyhelper.OrderByHelper; import java.math.BigDecimal; import java.math.RoundingMode; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; import static com.java2nb.novel.mapper.BookCategoryDynamicSqlSupport.bookCategory; @@ -201,9 +198,6 @@ public class BookServiceImpl implements BookService { PageHelper.startPage(page, pageSize); - if (StringUtils.isNotBlank(params.getSort())) { - OrderByHelper.orderBy(params.getSort() + " desc"); - } return PageBuilder.build(bookMapper.searchByPage(params)); } @@ -231,23 +225,22 @@ public class BookServiceImpl implements BookService { @Override public List queryIndexList(Long bookId, String orderBy, Integer page, Integer pageSize) { - if (StringUtils.isNotBlank(orderBy)) { - OrderByHelper.orderBy(orderBy); - } if (page != null && pageSize != null) { PageHelper.startPage(page, pageSize); } - - SelectStatementProvider selectStatement = select(BookIndexDynamicSqlSupport.id, + QueryExpressionDSL.QueryExpressionWhereBuilder where = select( + BookIndexDynamicSqlSupport.id, BookIndexDynamicSqlSupport.bookId, BookIndexDynamicSqlSupport.indexNum, BookIndexDynamicSqlSupport.indexName, BookIndexDynamicSqlSupport.updateTime, BookIndexDynamicSqlSupport.isVip) .from(bookIndex) - .where(BookIndexDynamicSqlSupport.bookId, isEqualTo(bookId)) + .where(BookIndexDynamicSqlSupport.bookId, isEqualTo(bookId)); + if("index_num desc".equals(orderBy)){ + where.orderBy(BookIndexDynamicSqlSupport.indexNum.descending()); + } + return bookIndexMapper.selectMany(where .build() - .render(RenderingStrategies.MYBATIS3); - - return bookIndexMapper.selectMany(selectStatement); + .render(RenderingStrategies.MYBATIS3)); } @@ -384,7 +377,6 @@ public class BookServiceImpl implements BookService { @Override public PageBean listCommentByPage(Long userId, Long bookId, int page, int pageSize) { PageHelper.startPage(page, pageSize); - OrderByHelper.orderBy("t1.create_time desc"); return PageBuilder.build(bookCommentMapper.listCommentByPage(userId, bookId)); } diff --git a/novel-front/src/main/java/com/java2nb/novel/vo/BookCommentVO.java b/novel-front/src/main/java/com/java2nb/novel/vo/BookCommentVO.java index 5b1e3c4..1d553cf 100644 --- a/novel-front/src/main/java/com/java2nb/novel/vo/BookCommentVO.java +++ b/novel-front/src/main/java/com/java2nb/novel/vo/BookCommentVO.java @@ -6,7 +6,6 @@ import com.java2nb.novel.core.serialize.CommentUserNameSerialize; import com.java2nb.novel.entity.BookComment; import lombok.Data; -import javax.annotation.Generated; import java.util.Date; /** diff --git a/novel-front/src/main/resources/application-dev.yml b/novel-front/src/main/resources/application-dev.yml index f0dbf87..5eda262 100644 --- a/novel-front/src/main/resources/application-dev.yml +++ b/novel-front/src/main/resources/application-dev.yml @@ -1,6 +1,6 @@ spring: - profiles: - include: [ common-dev ] + config: + import: classpath:application-common-dev.yml pic: diff --git a/novel-front/src/main/resources/application-prod.yml b/novel-front/src/main/resources/application-prod.yml index f55090d..5378c0f 100644 --- a/novel-front/src/main/resources/application-prod.yml +++ b/novel-front/src/main/resources/application-prod.yml @@ -1,6 +1,6 @@ spring: - profiles: - include: [ common-prod ] + config: + import: classpath:application-common-prod.yml #静态文件路径配置 resources: diff --git a/novel-front/src/main/resources/logback-boot.xml b/novel-front/src/main/resources/logback-boot.xml index ccc3d13..35f35cb 100644 --- a/novel-front/src/main/resources/logback-boot.xml +++ b/novel-front/src/main/resources/logback-boot.xml @@ -12,9 +12,6 @@ - ${CONSOLE_LOG_PATTERN} UTF-8 @@ -22,43 +19,43 @@ - - + + - - logs/novel-front.log + + logs/novel-front.log - - + + - - logs/debug.%d.%i.log + + logs/debug.%d{yyyy-MM-dd}.%i.log 30 - - - 10MB - + + 10MB + + 1GB - - %d %p (%file:%line\)- %m%n - + %d %p (%file:%line\)- %m%n UTF-8 + + - + - + - + \ No newline at end of file diff --git a/novel-front/src/main/resources/mybatis/mapping/BookCommentMapper.xml b/novel-front/src/main/resources/mybatis/mapping/BookCommentMapper.xml index 654b5a9..ea38ff2 100644 --- a/novel-front/src/main/resources/mybatis/mapping/BookCommentMapper.xml +++ b/novel-front/src/main/resources/mybatis/mapping/BookCommentMapper.xml @@ -14,7 +14,7 @@ and t1.create_user_id = #{userId} - + order by t1.create_time desc diff --git a/novel-front/src/main/resources/mybatis/mapping/BookMapper.xml b/novel-front/src/main/resources/mybatis/mapping/BookMapper.xml index b020f40..b986293 100644 --- a/novel-front/src/main/resources/mybatis/mapping/BookMapper.xml +++ b/novel-front/src/main/resources/mybatis/mapping/BookMapper.xml @@ -31,6 +31,9 @@ and last_index_update_time >= #{updateTimeMin} + + order by ${sort} desc + diff --git a/pom.xml b/pom.xml index 907434a..9152b2b 100644 --- a/pom.xml +++ b/pom.xml @@ -20,7 +20,7 @@ org.springframework.boot spring-boot-starter-parent - 2.7.18 + 3.4.0 @@ -30,11 +30,10 @@ 21 true 8.0.29 - 2.1.4 + 3.0.4 1.4.0 - 1.1.4 + 1.5.0 1.4.6 - 1.0.2 3.4 0.9.1 6.3.1