几年前问过的几乎相同的问题,但无济于事,我想是时候在这里问了。
为什么我的小组看到此Whilelabel错误页面? -> (https://i.imgur.com/hGd61Qr.png)
文件结构图1:https://i.imgur.com/x5Jn4gP.png
文件结构图2:https://i.imgur.com/K8gP59y.png
文件结构图3:https://i.imgur.com/JFFEidy.png
似乎我们具有Spring喜欢的一般结构,主应用程序位于所有其他控制器等之上。
MainApp类: 包com.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication(scanBasePackages = {"com.example.demo",
"com.example.demo.domain", "com.example.demo.dao",
"com.example.demo.service"})
@ComponentScan("com.example.demo.domain.Book_CopiesMapper")
public class MySpringBootApplication {
public static void main(String[] args) {
SpringApplication.run(MySpringBootApplication.class, args);
}
}
我们必须拥有那个ComponentScan,否则我们会收到此错误: https://i.imgur.com/BKDwHyn.png
控制器类:
package com.example.demo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.example.demo.domain.Borrower;
import com.example.demo.domain.Employee;
import com.example.demo.service.BorrowerService;
@RestController
public class LoginController {
@Autowired
BorrowerService borrowerService;
@GetMapping("/login")
public String login() {
System.out.println("hello from LoginController");
return "login";
}
@GetMapping("/signup")
public String signup() {
return "signup";
}
@RequestMapping(value = "/registerUser", method = RequestMethod.POST)
public String registerUser(@ModelAttribute Borrower borrower, Model model) {
borrowerService.insertBorrower(borrower);
model.addAttribute("message", "Success! You may now login with Card Number: " + borrower.getcardNo());
return "registerUser";
}
}
登录是一个简单的登录页面,注册是一种允许用户注册到我们的库的表单,registerUser用于连接到我们的Oracle SQL数据库并将用户插入到相应的表中(我们假设这是是正确的方法)
pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>MySpringBoot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>MySpringBoot</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>codelds</id>
<url>https://code.lds.org/nexus/content/groups/main-repo</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
application.properties:
#spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
spring.thymeleaf.cache = false
#mybatis
mybatis.type-aliases-package=com.example.demo.domain
spring.datasource.url = jdbc:oracle:thin:@dataserv.mscs.mu.edu:1521:orcl
spring.datasource.username =
spring.datasource.password =
spring.datasource.driver-class-name = oracle.jdbc.driver.OracleDriver
出于明显的原因,省略了数据库的用户名和密码。
如果任何人都可以提供反馈,我们将不胜感激!评论人们是否希望我发布其他图片或文件。
谢谢!
编辑:我们使用的路径是localhost:8080 / login或localhost:8080 / signup。目前看来,我们采取的任何路径都会导致此错误
此外,我们所有的DAO类都将@Autowired标记用于我们使用的任何服务,并且类似地,我们@Autowire使用其他类(例如Service包中的DAO)中需要的其他任何东西。抱歉,这句话有点含糊
答案 0 :(得分:0)
问题是因为您正在使用@RestController
,并且默认情况下您正在发送视图,其余控制器发送的消息将返回域对象/ pojo而不是视图,请用@Controller
替换它。希望对您有所帮助。