Spring 引导不生成 json 并显示白页
Spring boot does not generate the json and shows me the white page
我用 sql 服务器做了一个简单的列表,但它没有显示结果,只显示了白页。
我在控制台中没有错误。 sql 服务器 2017 会是吗?请帮忙?
连接到 sql 服务器 2017
spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.datasource.url=jdbc:sqlserver://localhost;databaseName=DB_PRUEBA_V1;integratedSecurity=true
spring.jpa.show-sql=true
#spring.jpa.hibernate.ddl-auto=update
server.port=8090
打包应用程序
package app;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class ProyectoV2Application {
public static void main(String[] args) {
SpringApplication.run(ProyectoV2Application.class, args);
}
}
套餐型号
package model;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "TB_USERS")
public class Users implements Serializable{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "COD_USER")
private int codUser;
@Column(name = "NOM_USER")
private String nomUser;
@Column(name = "EMA_USER")
private String emUser;
public int getCodUser() {
return codUser;
}
public void setCodUser(int codUser) {
this.codUser = codUser;
}
public String getNomUser() {
return nomUser;
}
public void setNomUser(String nomUser) {
this.nomUser = nomUser;
}
public String getEmUser() {
return emUser;
}
public void setEmUser(String emUser) {
this.emUser = emUser;
}
}
软件包存储库
package repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import model.Users;
@Repository
public interface UserDAO extends JpaRepository<Users, Integer>{
}
服务
package service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import model.Users;
import repository.UserDAO;
@Service
public class UserService {
@Autowired
private UserDAO dao;
public List<Users> lista(){
return dao.findAll();
}
}
包控制器
package controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import model.Users;
import service.UserService;
@RestController
@RequestMapping(value = "/CrudUsers")
public class UserController {
@Autowired
private UserService us;
@ResponseBody
@GetMapping(path = "/lista", produces = MediaType.APPLICATION_JSON_VALUE)
public List<Users> lista(){
return us.lista();
}
}
Whitelabel Error Page
因为您在不同的包中创建了每个 class,如下所示,
app --> ProyectoV2Application
model --> Users
repository --> UserDAO
service --> UserService
controller --> UserController
但是spring boot 会扫描根包或者根包的子包中的classes,所以将所有这些classes 移动到根包的子包中
app --> ProyectoV2Application
app.model --> Users
app.repository --> UserDAO
app.service --> UserService
app.controller --> UserController
我用 sql 服务器做了一个简单的列表,但它没有显示结果,只显示了白页。 我在控制台中没有错误。 sql 服务器 2017 会是吗?请帮忙?
连接到 sql 服务器 2017
spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.datasource.url=jdbc:sqlserver://localhost;databaseName=DB_PRUEBA_V1;integratedSecurity=true
spring.jpa.show-sql=true
#spring.jpa.hibernate.ddl-auto=update
server.port=8090
打包应用程序
package app;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class ProyectoV2Application {
public static void main(String[] args) {
SpringApplication.run(ProyectoV2Application.class, args);
}
}
套餐型号
package model;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "TB_USERS")
public class Users implements Serializable{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "COD_USER")
private int codUser;
@Column(name = "NOM_USER")
private String nomUser;
@Column(name = "EMA_USER")
private String emUser;
public int getCodUser() {
return codUser;
}
public void setCodUser(int codUser) {
this.codUser = codUser;
}
public String getNomUser() {
return nomUser;
}
public void setNomUser(String nomUser) {
this.nomUser = nomUser;
}
public String getEmUser() {
return emUser;
}
public void setEmUser(String emUser) {
this.emUser = emUser;
}
}
软件包存储库
package repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import model.Users;
@Repository
public interface UserDAO extends JpaRepository<Users, Integer>{
}
服务
package service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import model.Users;
import repository.UserDAO;
@Service
public class UserService {
@Autowired
private UserDAO dao;
public List<Users> lista(){
return dao.findAll();
}
}
包控制器
package controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import model.Users;
import service.UserService;
@RestController
@RequestMapping(value = "/CrudUsers")
public class UserController {
@Autowired
private UserService us;
@ResponseBody
@GetMapping(path = "/lista", produces = MediaType.APPLICATION_JSON_VALUE)
public List<Users> lista(){
return us.lista();
}
}
Whitelabel Error Page
因为您在不同的包中创建了每个 class,如下所示,
app --> ProyectoV2Application
model --> Users
repository --> UserDAO
service --> UserService
controller --> UserController
但是spring boot 会扫描根包或者根包的子包中的classes,所以将所有这些classes 移动到根包的子包中
app --> ProyectoV2Application
app.model --> Users
app.repository --> UserDAO
app.service --> UserService
app.controller --> UserController