首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring不工作[小写字母][大写字母]类型参数

Spring不工作[小写字母][大写字母]类型参数
EN

Stack Overflow用户
提问于 2018-12-11 16:38:58
回答 1查看 328关注 0票数 0

嗨~我在使用时遇到了麻烦。这个故障github url:保存/树结构-ztree

开发环境-启动-启动-父程序:2.0.6. reference + JPA + H2 spring数据jpa引用:https://docs.spring.io/spring-data/jpa/docs/current/reference/html/

一切都很好。除了一个。

不要工作参数类型:小字母.( ex) tId

如果把{tId}改为{tempId}是好工作!但是我想使用{tId}

ZTreeService.java

代码语言:javascript
复制
good work! no problem exmaple!!!

(O) zTrees = zTreeRepository.findAllByOrderById();
(O) zTrees = zTreeRepository.findAllByOrderByName();
(O) zTrees = zTreeRepository.findAllByOrderByIsParent();

don't work! only this type exmaple!!! why~

(X) zTrees = zTreeRepository.findAllByOrderByTId();

tId类型参数可能创建,插入从春季数据JPA。但是“OrderBy”方法不支持小字母类型参数吗?

ZTree.java

代码语言:javascript
复制
package com.github.moregorenine.ztree.domain;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Transient;
import javax.validation.constraints.NotBlank;

@Entity
public class ZTree {
    @Id
    @GeneratedValue
    private Long id; // 본인 id
    private String tId; // Ztree 내장 id
    @Transient
    private String parentTId; // Ztree 내장 pId
    @Transient
    private Long level; // lvl : 같은 그룹내 계층
    @NotBlank(message = "Name을 작성해주세요.")
    private String name;
    private String isParent;
    private String url; // 메뉴에 연결할 url
    private String useYn; // 메뉴 사용여부
    @ManyToOne(cascade={CascadeType.ALL})
    @JoinColumn(name="pId")
    private ZTree parent;
    @OneToMany(mappedBy="parent", cascade={CascadeType.ALL})
    private Set<ZTree> children = new HashSet<ZTree>();
}

ZTreeService.java

代码语言:javascript
复制
@Service
public class ZTreeService {

    @Autowired
    private ZTreeRepository zTreeRepository;

    public List<ZTree> getAllZTrees() {
        List<ZTree> zTrees = new ArrayList<>();
        zTrees = zTreeRepository.findAllByOrderByTId();
        return zTrees;
    }
}

H2数据库

在这里输入图像描述

生成失败消息

代码语言:javascript
复制
org.springframework.beans.factory.UnsatisfiedDependencyException:
    Error creating bean with name 'ZTreeController': Unsatisfied dependency expressed through field 'zTreeService';
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException:
    Error creating bean with name 'ZTreeService': Unsatisfied dependency expressed through field 'zTreeRepository';
nested exception is org.springframework.beans.factory.BeanCreationException:
    Error creating bean with name 'ZTreeRepository': Invocation of init method failed;
nested exception is java.lang.IllegalArgumentException:
    Failed to create query for method public abstract java.util.List com.github.moregorenine.ztree.repository.ZTreeRepository.findAllByOrderByTId()! Unable to locate Attribute  with the the given name [TId] on this ManagedType [com.github.moregorenine.ztree.domain.ZTree]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:584) ~[spring-beans-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:90) ~[spring-beans-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:370) ~[spring-beans-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1336) ~[spring-beans-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:572) ~[spring-beans-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495) ~[spring-beans-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:759) ~[spring-beans-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:548) ~[spring-context-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.6.RELEASE.jar:2.0.6.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) [spring-boot-2.0.6.RELEASE.jar:2.0.6.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:386) [spring-boot-2.0.6.RELEASE.jar:2.0.6.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) [spring-boot-2.0.6.RELEASE.jar:2.0.6.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1242) [spring-boot-2.0.6.RELEASE.jar:2.0.6.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1230) [spring-boot-2.0.6.RELEASE.jar:2.0.6.RELEASE]
    at com.github.moregorenine.TreeStructureZtreeApplication.main(TreeStructureZtreeApplication.java:10) [classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_152]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_152]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_152]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_152]
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.0.6.RELEASE.jar:2.0.6.RELEASE]
EN

回答 1

Stack Overflow用户

发布于 2018-12-28 16:09:29

我用“排序”代替“OrderByTid”

zTrees = zTreeRepository.findAll(new Sort(Sort.Direction.ASC, "tId"));

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53728591

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档