基于模型 - 视图 - 控制器(MVC)模式构建Java Web应用程序的框架。它从底层视图技术中提升灵活和分离的代码。
Spring Security BadCredentialsException
我正在遵循这个 Baeldung 教程,我看不到任何差异(除了预生成的登录页面模板),但在尝试使用硬
下面是根据新的 Spring Security 6 / Spring boot 3 文档创建的 SecurityFilterChain bean。请告诉我这是预期的结果还是出现问题。 代码 : @配置...
Thymeleaf th:each - 如何禁用生成 div 标签
<div class="question" th:each="question : ${questions}"> <h2 id="question" class="description" th:text="${question.description}">Question goes here</h2> <div id="answer-buttons"> <button class="btn"><div class="answer" th:text="${question.possibleAnswers.get(0).content}" th:classappend="${question.correctAnswer == 1 ? 'correct-answer' : ''}">Answer 1</div></button> <button class="btn"><div class="answer" th:text="${question.possibleAnswers.get(1).content}" th:classappend="${question.correctAnswer == 2 ? 'correct-answer' : ''}">Answer 2</div></button> <button class="btn"><div class="answer" th:text="${question.possibleAnswers.get(2).content}" th:classappend="${question.correctAnswer == 3 ? 'correct-answer' : ''}">Answer 3</div></button> <button class="btn"><div class="answer" th:text="${question.possibleAnswers.get(3).content}" th:classappend="${question.correctAnswer == 4 ? 'correct-answer' : ''}">Answer 4</div></button> </div> <button id="next-btn">Next</button> </div> 如果我没猜错的话,上面代码中的th:each会为问题中的每个问题进行新的划分,类似于: <div class="quiz"> <div class="question"> <h2 id="question" class="description">Question</h2> <div id="answer-buttons"> <button class="btn"><div class="answer">Answer 1</div></button> <button class="btn"><div class="answer correct-answer">Answer 2</div></button> <button class="btn"><div class="answer">Answer 3</div></button> <button class="btn"><div class="answer">Answer 4</div></button> </div> <button id="next-btn">Next</button> </div> </div> 问题来自数据库,我有 js 文件来处理它们,但为了做到这一点,我不想创建额外的 html 正文。 所以我的问题是,Thymeleaf 是否有一些针对上述问题的禁用机制,或者我是否需要更改代码结构? 对于任何用途,以下是我的脚本处理数据的方式: const questionsFromDb = document.querySelectorAll('.question'); // Template const questions = [ { question: "Which is the largest animal on the planet?", answers: [ {text: "Shark", correct: false}, {text: "Blue whale", correct: true}, {text: "Elephant", correct: false}, {text: "Giraffe", correct: false} ] }, { question: "Which is the smallest country on the planet?", answers: [ {text: "Vatican City", correct: true}, {text: "Bhutan", correct: false}, {text: "Nepal", correct: false}, {text: "Shri Lanka", correct: false} ] }, { question: "Which is the largest desert on the planet?", answers: [ {text: "Kalahari", correct: false}, {text: "Gobi", correct: false}, {text: "Sahara", correct: false}, {text: "Antarctica", correct: true} ] }, { question: "Which is the smallest continent on the planet?", answers: [ {text: "Asia", correct: false}, {text: "Australia", correct: true}, {text: "Arctic", correct: false}, {text: "Africa", correct: false} ] } ]; // Parsing Data questionsFromDb.forEach(questionFromDb => { const questionDescription = questionFromDb.querySelector('.description').innerText; const answerElements = questionFromDb.querySelectorAll('.answer'); const answers = []; answerElements.forEach((answerElement, index) => { const answerText = answerElement.innerText; const isCorrect = answerElement.classList.contains('correct-answer'); answers.push({ text: answerText, correct: isCorrect }); }); questions.push({ question: questionDescription, answers: answers }); }); // ... Non-relative code below 添加新的 div 是一种有效的方法,你可以有额外的没有样式的 div,但是如果你想删除标签,你可以使用 th:remove="tag" 或 th:inline 机制,但这不是样式测试的好方法,尊重表达式语言方法,添加 html id 也不是正确的方法,您可以向 id 添加其他数据,例如:th:id="${'question_'+ status.id}" . 而且你的模板似乎是json! 如果你问我,我认为最好的方法是不要在这样的列表 ui 中使用 thymleaf,你可以使用 js 数据表,例如 tabulator 休息并玩 js 来代替
我正在为我的项目使用 Java Spring Boot,并且我有以下控制器: @AllArgsConstructor @RestController @RequestMapping("/api/subject") 公共类SubjectController { 公关...
这是来自 tomcat 日志文件夹的详细日志上下文 2024 年 3 月 30 日 10:26:42.230 严重 [main] org.apache.catalina.core.StandardContext.filterStart 异常启动过滤器 [authenticationTokenFilterBe...
我正在为我的项目使用 Java Spring Boot,并且我有以下控制器: @AllArgsConstructor @RestController @RequestMapping("/api/subject") 公共类SubjectController { 公关...
在spring mvc项目中运行junit测试时出现此错误。 引起的原因:org.springframework.beans.factory.BeanCreationException:创建名称为“createWebSocketContainer”的 bean 时出错
如何在 Spring MVC 中启用 CORS 进行错误响应?
我正在开发一个应用程序,我使用 Spring MVC 作为后端,使用 Angular5 作为前端。我一直坚持 Auth2 安全层的实现,包括跨源资源共享......
不接受 Spring MVC ResponseEntity<Resource> 输入流资源?
我正在尝试使用 ResponseEntity 作为控制器方法响应类型,通过 Spring MVC 发送 jpg 图像。 如果资源是 FileSystemResource,它工作正常,但是当我尝试...
我使用 @ExtendsWith(MockitoExtension.class) 和 @SpringBootTest 任何人都可以用示例来澄清我
我是Spring boot的初学者,到目前为止我已经完成了以MYSQL作为数据库的REST操作(GET,POST,PUT,DELETE),我想为Controller类和Service类编写单元测试用例......
是否可以在Spring MVC REST端点中验证@RequestParam?
在 Jersey 2 中可以这样做: @得到 @PATH("用户/{电子邮件}") 公共 IDto getUser(@NotNull @Email @PathParam("email") String validEmail) { 返回 userManagementService.findUserByEmail(vali...
maven clean install 和 mvn spring-boot:run 在 POST 请求上给我 401(未经授权)错误
当我使用“mvn clean package”和“mvn spring-boot:run”运行我的java spring boot项目时,我收到 POST http://localhost:8080/api/v1/register 401(未经授权)错误。当我
任何人都可以告诉我这段代码中缺少什么吗? Spring Boot 3.2.3 和此 dep 已就位: org.springframework.boot 春天...
我的这段代码有问题...... 当我运行应用程序时,它会转到登录页面而不是索引页面。 这是我的安全配置: 受保护的无效配置(HttpSecurity http)
在 Spring Boot 中重定向到“/create”时出现问题
我有这个 ProductController.java 代码片段: @GetMapping("/创建") 公共字符串showCreatePage(模型模型){ ProductDto ProductDto = new ProductDto(); model.addAttribute(&...
`我正在使用 spring MVC,想要从 React.js 发送请求,但是 CORS 问题如何使用 ApplicationContext.xml 在 spring mvc 中启用它 我已在 applicationcontex 中添加了这些行...
使用 maven 依赖项的 SPRINGBOOT 应用程序中除了 MONGO_CLUSTER 之外,每个环境变量都可以工作
使用Maven依赖 我保罗施瓦茨 spring-dotenv 2.5.4 使用Maven依赖 <dependency> <groupId>me.paulschwarz</groupId> <artifactId>spring-dotenv</artifactId> <version>2.5.4</version> </dependency> applications.properties 文件 spring.data.mongodb.database=${env.MONGO_DATABASE} spring.data.mongodb.uri=mongodb+srv://${MONGO_USER}:${MONGO_PASSWORD}@${MONGO_CLUSTER} 错误:- Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled. 2023-10-10T16:12:28.505+05:30 ERROR 20008 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongo' defined in class path resource [org/springframework/boot/autoconfigure/mongo/MongoAutoConfiguration.class]: Failed to instantiate [com.mongodb.client.MongoClient]: Factory method 'mongo' threw exception with message: An SRV host name '${MONGO_CLUSTER}' was provided that does not contain at least three parts. It must contain a hostname, domain name and a top level domain. at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:654) ~[spring-beans-6.0.12.jar:6.0.12] at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:642) ~[spring-beans-6.0.12.jar:6.0.12] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1332) ~[spring-beans-6.0.12.jar:6.0.12] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1162) ~[spring-beans-6.0.12.jar:6.0.12] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:560) ~[spring-beans-6.0.12.jar:6.0.12] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:520) ~[spring-beans-6.0.12.jar:6.0.12] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:325) ~[spring-beans-6.0.12.jar:6.0.12] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-6.0.12.jar:6.0.12] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:323) ~[spring-beans-6.0.12.jar:6.0.12] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-6.0.12.jar:6.0.12] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:973) ~[spring-beans-6.0.12.jar:6.0.12] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:942) ~[spring-context-6.0.12.jar:6.0.12] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:608) ~[spring-context-6.0.12.jar:6.0.12] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[spring-boot-3.1.4.jar:3.1.4] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737) ~[spring-boot-3.1.4.jar:3.1.4] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:439) ~[spring-boot-3.1.4.jar:3.1.4] at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-3.1.4.jar:3.1.4] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1309) ~[spring-boot-3.1.4.jar:3.1.4] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1298) ~[spring-boot-3.1.4.jar:3.1.4] at dev.mercifulsamurai.movies.MoviesApplication.main(MoviesApplication.java:11) ~[classes/:na] at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:578) ~[na:na] at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:50) ~[spring-boot-devtools-3.1.4.jar:3.1.4] Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.mongodb.client.MongoClient]: Factory method 'mongo' threw exception with message: An SRV host name '${MONGO_CLUSTER}' was provided that does not contain at least three parts. It must contain a hostname, domain name and a top level domain. at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:171) ~[spring-beans-6.0.12.jar:6.0.12] at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:650) ~[spring-beans-6.0.12.jar:6.0.12] ... 22 common frames omitted Caused by: java.lang.IllegalArgumentException: An SRV host name '${MONGO_CLUSTER}' was provided that does not contain at least three parts. It must contain a hostname, domain name and a top level domain. at com.mongodb.connection.ClusterSettings.<init>(ClusterSettings.java:594) ~[mongodb-driver-core-4.9.1.jar:na] at com.mongodb.connection.ClusterSettings.<init>(ClusterSettings.java:50) ~[mongodb-driver-core-4.9.1.jar:na] at com.mongodb.connection.ClusterSettings$Builder.build(ClusterSettings.java:370) ~[mongodb-driver-core-4.9.1.jar:na] at com.mongodb.MongoClientSettings.<init>(MongoClientSettings.java:957) ~[mongodb-driver-core-4.9.1.jar:na] at com.mongodb.MongoClientSettings.<init>(MongoClientSettings.java:64) ~[mongodb-driver-core-4.9.1.jar:na] at com.mongodb.MongoClientSettings$Builder.build(MongoClientSettings.java:600) ~[mongodb-driver-core-4.9.1.jar:na] at org.springframework.boot.autoconfigure.mongo.MongoClientFactorySupport.createMongoClient(MongoClientFactorySupport.java:50) ~[spring-boot-autoconfigure-3.1.4.jar:3.1.4] at org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration.mongo(MongoAutoConfiguration.java:59) ~[spring-boot-autoconfigure-3.1.4.jar:3.1.4] at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:578) ~[na:na] at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:139) ~[spring-beans-6.0.12.jar:6.0.12] ... 23 common frames omitted Process finished with exit code 0 这在某种程度上有效,但我不应该这样使用它 spring.data.mongodb.database=${env.MONGO_DATABASE} spring.data.mongodb.uri=mongodb+srv://${MONGO_USER}:${MONGO_PASSWORD}@cluster0.*******.mongodb.net 从属性文件的第一行中删除 env.。
Spring MVC 使用 Produce 指令请求排序的问题
我有一堂课: @PostMapping(path = "/api/v1/chat/completions", 产生 = {MediaType.TEXT_EVENT_STREAM_VALUE}) 公共 Flux 流完成(@RequestBody
仅当用户具有特定角色时,如何使用 th:classappend 将类附加到元素? 像这样的东西: 我正在使用
为什么 ${message} 出现在 View 中,而不是 Spring MVC 控制器中传递的真实消息
我正在尝试学习 Spring MVC 并遇到了一个问题。请参阅随附的代码。我没有在视图上收到真正的消息,而是在视图上收到 ${message} 。这里可能有什么问题? 这是...