我得到一个例外。请求处理失败;嵌套异常是 org.springframework.data.mapping.PropertyReferenceException: No property start found for type.. 我不知道这段代码有什么问题,但我几乎在后端使用所有这些原则做了所有事情,似乎缺少一些东西。 .
控制器
@RequestMapping(value = "/pages/{pageNumber}", method = RequestMethod.GET)
public String getStories(@PathVariable Integer pageNumber, Model model) {
Page<Article> page = frontService.getStories(pageNumber);
int current = page.getNumber() + 1;
int begin = Math.max(1, current - 5);
int end = Math.min(begin + 10, page.getTotalPages());
model.addAttribute("deploymentLog", page);
model.addAttribute("beginIndex", begin);
model.addAttribute("endIndex", end);
model.addAttribute("currentIndex", current);
return "NewFile";
}
服务
public interface FrontStoryService {
public Page<Article> getStories(Integer pageNumber);
}
服务实现
@Service
@Transactional
public class FrontStoryServiceImpl implements FrontStoryService {
private static final int PAGE_SIZE = 50;
@Inject private FrontEndStoriesRepository storiesRepo;
public Page<Article> getStories(Integer pageNumber) {
PageRequest request =
new PageRequest(pageNumber - 1, PAGE_SIZE, Sort.Direction.DESC, "startTime");
System.out.println(request);
return storiesRepo.findAll(request);
}
}
回购
@Repository("frontService")
public interface FrontEndStoriesRepository extends JpaRepository<Article, Long> { }
错误:
org.springframework.data.mapping.PropertyReferenceException: No property start found for type com.jwlayug.atriev.model.Article
org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:75)
org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:327)
org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:353)
org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:307)
org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:271)
org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:245)
org.springframework.data.jpa.repository.query.QueryUtils.toJpaOrder(QueryUtils.java:401)
org.springframework.data.jpa.repository.query.QueryUtils.toOrders(QueryUtils.java:365)
org.springframework.data.jpa.repository.support.SimpleJpaRepository.getQuery(SimpleJpaRepository.java:449)
org.springframework.data.jpa.repository.support.SimpleJpaRepository.getQuery(SimpleJpaRepository.java:430)
org.springframework.data.jpa.repository.support.SimpleJpaRepository.findAll(SimpleJpaRepository.java:312)
org.springframework.data.jpa.repository.support.SimpleJpaRepository.findAll(SimpleJpaRepository.java:282)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:606)
org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:333)
org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:318)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:155)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
org.springframework.data.jpa.repository.support.LockModeRepositoryPostProcessor$LockModePopulatingMethodIntercceptor.invoke(LockModeRepositoryPostProcessor.java:92)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:91)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
com.sun.proxy.$Proxy43.findAll(Unknown Source)
com.jwlayug.atriev.service.FrontStoryServiceImpl.getStories(FrontStoryServiceImpl.java:25)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:606)
org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
com.sun.proxy.$Proxy44.getStories(Unknown Source)
com.jwlayug.atriev.controller.FrontController.getStories(FrontController.java:39)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:606)
org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:180)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
模型
import org.hibernate.annotations.Type;
@Entity
@Table(name="tblArticle")
public class Article {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long articleID;
private String title;
private String author;
@Type(type="text")
private String content;
@Temporal(TemporalType.TIMESTAMP)
@Column(nullable=false)
private Date dateCreated;
@Temporal(TemporalType.TIMESTAMP)
@Column(nullable=false)
private Date dateUpdated;
private boolean publish;
private boolean send;
@ManyToOne(targetEntity=UserSession.class,cascade=CascadeType.ALL)
private UserSession userSession;
@OneToMany(mappedBy="mail", cascade=CascadeType.ALL,fetch=FetchType.LAZY)
private List<Recipient> sendEmail = new ArrayList<Recipient>();
@ManyToOne(targetEntity=Media.class,cascade=CascadeType.ALL)
private Media media;
public Article(){}
public Article(String title, String author,
String content,UserSession userSession) {
super();
this.title = title;
this.author = author;
this.content = content;
this.dateCreated = new Date();
this.dateUpdated = new Date();
this.send = false;
this.publish = false;
this.userSession = userSession;
}
public Long getArticleID() {
return articleID;
}
public String getAuthor() {
return author;
}
public String getContent() {
return content;
}
public Date getDateCreated() {
return dateCreated;
}
public Date getDateUpdated() {
return dateUpdated;
}
public Media getMedia() {
return media;
}
public List<Recipient> getSendEmail() {
return sendEmail;
}
public String getTitle() {
return title;
}
public UserSession getUserSession() {
return userSession;
}
public boolean isPublish() {
return publish;
}
public boolean isSend() {
return send;
}
public void setArticleID(Long articleID) {
this.articleID = articleID;
}
public void setAuthor(String author) {
this.author = author;
}
public void setContent(String content) {
this.content = content;
}
public void setDateCreated(Date dateCreated) {
this.dateCreated = dateCreated;
}
public void setDateUpdated(Date dateUpdated) {
this.dateUpdated = dateUpdated;
}
@PrePersist
protected void onCreate() {
dateUpdated = dateCreated = new Date();
}
@PreUpdate
protected void onUpdate() {
dateUpdated = new Date();
}
public void setMedia(Media media) {
this.media = media;
}
public void setPublish(boolean publish) {
this.publish = publish;
}
public void setSend(boolean send) {
this.send = send;
}
public void setSendEmail(List<Recipient> sendEmail) {
this.sendEmail = sendEmail;
}
public void setTitle(String title) {
this.title = title;
}
public void setUserSession(UserSession userSession) {
this.userSession = userSession;
}
}