The Repository rest resouce gives me links for each resource like for id 1 it gives me their whole record thats in the h2 db and if i type in the id as resource like aliens/{any_id} then it gives me that record. Over here, I want it so if i type aliens/{any_name} it should give me a record with that name on it. Is it possible? i've made a workaround by using built in method in interface where a list of that record is given and i can use it from the controller and return it as data in the form of list
Controller code
package com.example.demo.model.RestController;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import com.example.demo.AlienRepo;
import com.example.demo.model.Alien;
@RestController
public class RestControl {
@Autowired
AlienRepo ar;
@GetMapping(path="/aliens/{aname}")
public List<Alien> getByName(@PathVariable("aname") String name){
return ar.findByAname(name);
}
}
Interface or Repository code
package com.example.demo;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import com.example.demo.model.Alien;
@RepositoryRestResource(collectionResourceRel="aliens",path="aliens")
public interface AlienRepo extends JpaRepository<Alien, Integer>{
List<Alien> findByAname(String aname);
}
my model contains the aid set with @Id, aname as String and tech as String