Spring Boot වල MySql Database Queries භාවිතා කරන්නේ කොහමද ??
මම Spring Boot භාවිතා කරල API එකක් හදලයි තියේන්නේ. මෙහිදි පාවිච්චි කරේ Spring JPA. මේ API එකේ GET request එකේදි දැනට table තියේන සියලුම Data පෙන්වනවා. මට ඕන , සියලුම Data නැතුව Columns 3ක් විතරක් පෙන්වන්න. ඒ කිව්වේ, JPA එක්ක, මේ වගේ "SELECT devname,hrs,ot FROM imaginaryTable" එකක් පාවිච්චි කරන්නේ කොහමද ??
Controller class එක.
Repository interface එක.
මම Spring Boot භාවිතා කරල API එකක් හදලයි තියේන්නේ. මෙහිදි පාවිච්චි කරේ Spring JPA. මේ API එකේ GET request එකේදි දැනට table තියේන සියලුම Data පෙන්වනවා. මට ඕන , සියලුම Data නැතුව Columns 3ක් විතරක් පෙන්වන්න. ඒ කිව්වේ, JPA එක්ක, මේ වගේ "SELECT devname,hrs,ot FROM imaginaryTable" එකක් පාවිච්චි කරන්නේ කොහමද ??
Controller class එක.
Code:
@RestController
@RequestMapping("/api")
public class ImController {
@Autowired
private ImRepository TaskRepository;
@GetMapping("/projects")
public List<ImModel> findAll() {
return (List<ImModel>) TaskRepository.findAll();
}
@GetMapping("/developers/{id}")
public ImModel findByName(@PathVariable final int id){
return TaskRepository.findById(id);
}
}
Repository interface එක.
Code:
package com.kisalka.pacrestapi.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import com.kisalka.pacrestapi.model.ImModel;
public interface ImRepository extends JpaRepository<ImModel, Integer> {
ImModel findById(int id);
}

