我开发了一个springbootweb应用程序,并尝试使用以下控制器实现从mysql数据库中逐个用户地检索电子邮件。
@RequestMapping("/api/v1/")
@RestController()
public class UserController {
private UserService userService;
public UserController(UserService userService) {
this.userService = userService;
}
@GetMapping("/users/email/{email}")
public User findUserByPrincipalId(@PathVariable String email) {
return userService.getUserByPrincipalId(email);
}
}
@Repository
public interface UserRepository extends CrudRepository<User, Long> {
User getUserByPrincipalId(String principalId);
Boolean existsByPrincipalId(String principalId);
}
这是用户实体类。
@Entity(name = "sys_user")
@Table(name = "sys_user", schema = "mobile")
public class User {
@Id
@Column(name = "id")
@GeneratedValue(strategy= GenerationType.IDENTITY)
private long id;
@Basic
@Column(name = "principal_id")
private String principalId;
@Basic
@Column(name = "passwd")
private String password;
@Basic
@Column(name = "prefixName")
private String prefix = "";
@Basic
@Column(name = "firstName")
private String firstName = "";
@Basic
@Column(name = "middleIntial")
private String middleInitial = "";
@Basic
@Column(name = "lastName")
private String lastName = "";
@Basic
@Column(name = "contactTypeId")
private long contactTypeId = 0;
@Basic
@Column(name = "phone")
private String phone = "";
@Basic
@Column(name = "fax")
private String fax = "";
@Basic
@Column(name = "mobile")
private String mobile = "";
@Basic
@Column(name = "lastLogon")
private Date lastLogon;
@Basic
@Column(name = "lastIP")
private String lastIP;
@Basic
@Column(name = "status")
private int status;
@Basic
@Column(name = "loginsInPeriod")
private int logInsInPeriod;
@Basic
@Column(name = "createdOn")
private Date createdOn;
@Basic
@Column(name = "lastModified")
private Date lastModified;
@Basic
@Column(name = "secondaryemail")
private String secondaryEmail;
@Basic
@Column(name = "salt")
private String salt;
@Basic
@Column(name = "certStatus")
private short certstatus;
@OneToMany
@JoinColumn(name = "id")
private List<UserRole> userRoles;
...
}
属性.yaml
spring:
profiles: local
datasource:
url: jdbc:mysql://localhost:3306/jacplus?serverTimezone=UTC
username: abc
password: abc
driver-class-name: com.mysql.cj.jdbc.Driver
jpa:
hibernate:
naming:
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
这是mysql数据库中的表结构。
表:系统用户
Columns:
id bigint(20) AI PK
principal_id varchar(64)
passwd varchar(128)
prefixName char(8)
firstName varchar(32)
middleIntial char(1)
lastName varchar(32)
contactTypeId bigint(20)
phone char(20)
fax char(20)
mobile char(20)
lastLogon timestamp
lastIP varchar(64)
status smallint(6)
loginsInPeriod int(11)
createdOn datetime
lastModified datetime
secondaryemail varchar(64)
salt varchar(64)
certStatus smallint(6)
但是当我调用controller类中的以下端点时。http://localhost:8082/api/v1/users/email/test@gmail.com
我在运行时遇到以下异常。
org.hibernate.exception.SQLGrammarException: could not extract ResultSet
at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java
:63)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConv
erter.java:42)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:67)
at org.hibernate.loader.Loader.getResultSet(Loader.java:2292)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:2050)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:2012)
Caused by: java.sql.SQLSyntaxErrorException: Unknown column
'user0_.cert_status' in 'field list'
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:953)
at com.mysql.cj.jdbc.ClientPreparedStatement.executeQuery(ClientPreparedStatement.java:1003)
at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52)
at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:57)
... 181 common frames omitted 2020-12-17 18:00:47,532 WARN jacplus-subscriptions-service [XNIO-5 task-1] fcd93f1a-3503-4b
我花了很多时间在网上寻找解决这个问题的方法。但我还是找不到解决办法。
暂无答案!
目前还没有任何答案,快来回答吧!