2

i have tried this problems to solve more than couple of hours but i could not, i basically trying to do crud operation but when i used save method for location for service implementation its show the error" inferred type 'S' for type parameter 'S' is not within its bound ; should extend 'java.lang.Integer' " so what are the steps to get rid of this massage

Repository Interface

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> {

}

locationServices

 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;
    }
}
rohit tamang
  • 81
  • 2
  • 3
  • 10

2 Answers2

3

I think you should change the order of the type parameters in the CrudRepository.

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

}

Looking at the Repository Javadoc, it gives us more clues about the Type Parameters:

Type Parameters:
T - the domain type the repository manages
ID - the type of the id of the entity the repository manages

Alexandru Somai
  • 1,395
  • 1
  • 7
  • 16
0

thanks everyOne for this help .actually i forget to implement thymleaf dependencies in to my pom.xml that was stupid mistake

rohit tamang
  • 81
  • 2
  • 3
  • 10