解决 无法返回页面,找不到静态资源,无法返回json等问题
跳转一个html
@CrossOrigin(origins = "*", allowedHeaders = "*")
@Controller
public class Text {
@RequestMapping("/login")
public String hello() {
return "/login.html";
}
}
跳转文字
@CrossOrigin(origins = "*", allowedHeaders = "*")
@RestController
public class Text {
@RequestMapping("/login")
public String hello() {
return "/login.html";
}
}
跳转好多个页面
1、maven添加
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
2、application.yaml
静态资源放置在static下,和prefix对应
server:
port: 8080
spring:
datasource:
username: root
password: 123456
url: jdbc:mysql://localhost/aaa?useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=GMT
driver-class-name: com.mysql.jdbc.Driver
mvc:
view:
suffix: .html
prefix: classpath:/static/
3、
class
- 前面要加斜线
- 要写页面名
- RequestMapping里面不写.html
- RequestMapping前面写斜线
- return 里面 要加.html
- 注释要记得修改为Controller, 不是RestController
@CrossOrigin(origins = "*", allowedHeaders = "*")
@Controller
public class ChangeHtml {
@RequestMapping("/index1")
public String hello() {
return "/index1.html";
}
@RequestMapping("/index2")
public String hello2() {
return "/index2.html";
}
}