【问题标题】:infrred type 'S' for type parameter 'S' is not within its bound ; should extend 'java.lang.Integer'类型参数“S”的红外类型“S”不在其范围内;应该扩展'java.lang.Integer'
【发布时间】:2020-02-25 13:12:12
【问题描述】:

我已经尝试解决这个问题超过几个小时,但我不能, 我基本上是在尝试进行 crud 操作,但是当我使用保存方法进行服务实现时,它会显示错误“推断类型参数‘S’的类型‘S’不在其范围内;应该扩展‘java.lang.Integer’”那么摆脱这种按摩的步骤是什么

存储库接口

package com.crudeoperation.demopro.Repo;

import com.crudeoperation.demopro.Entities.Location;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;


@Repository

public interface LocationRepository extends CrudRepository<Integer, Location> {

}

定位服务

 package com.crudeoperation.demopro.Services;

    import com.crudeoperation.demopro.Entities.Location;

    import java.util.List;
    import java.util.Optional;

    public interface LocationServices {
        Location saveLocation(Location location );
        Location UpdateLocation(Location location);
        void deleteLocation(Location location);
        Optional<Integer> getLocationById(int id);
        List<Location> getAllLocation();

    }

LocationServicesImpl

package com.crudeoperation.demopro.Services;

import com.crudeoperation.demopro.Entities.Location;
import com.crudeoperation.demopro.Repo.LocationRepository;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Optional;

public class LocationServicesImpl implements LocationServices {
    @Autowired
    private LocationRepository locationRepository;
    @Override
    public Location saveLocation(Location location) {
        return locationRepository.save(location);
    }

    @Override
    public Location UpdateLocation(Location location) {
        return null;
    }

    @Override
    public void deleteLocation(Location location) {

    }

    @Override
    public Optional<Integer> getLocationById(int id) {
        return Optional.empty();
    }

    @Override
    public List<Location> getAllLocation() {
        return null;
    }
}

【问题讨论】:

    标签: java spring-boot-maven-plugin


    【解决方案1】:

    我认为你应该改变CrudRepository中类型参数的顺序。

    @Repository
    public interface LocationRepository extends CrudRepository<Location, Integer> {
    
    }
    

    查看Repository Javadoc,它为我们提供了更多关于类型参数的线索:

    类型参数:
    T - 存储库管理的域类型
    ID - 存储库管理的实体的 ID 类型

    【讨论】:

      【解决方案2】:

      感谢每个人的帮助。实际上我忘记在我的 pom.xml 中实现 thymleaf 依赖项 那是愚蠢的错误

      【讨论】:

        猜你喜欢
        • 2019-03-09
        • 1970-01-01
        • 1970-01-01
        • 2019-03-25
        • 1970-01-01
        • 1970-01-01
        • 2011-05-24
        • 2021-11-13
        • 1970-01-01
        相关资源
        最近更新 更多