我有一个连接到SQL数据库并具有多个实体的Web应用程序。
主表是;
我正在尝试创建一种方法,该方法根据用户输入的名称来查询角色,获取角色ID,然后查询SkillxRole表,并返回与该角色ID相关联的所有技能的字符串数组。
如何使用用户指定的参数在Crud存储库中进行查询。这将通过使用ajax的html输入框输入,然后假定一个有效的端点。
任何帮助将不胜感激。以下是我想在其中查询我的存储库的searchController代码。
@Controller
public class SearchController {
public EmployeeRepository employeeRepository;
public RoleRepository roleRepository;
public SkillRepository skillRepository;
public roleSkillRatingsRepository roleSkillRatingsRepository;
@Autowired
public void employeeRepository(EmployeeRepository employeeRepository){
this.employeeRepository = employeeRepository;
}
@Autowired
public void roleRepository(RoleRepository roleRepository){
this.roleRepository = roleRepository;
}
@Autowired
public void skillRepository(SkillRepository skillRepository){
this.skillRepository = skillRepository;
}
@Autowired
public void roleSkillRatingsRepository(roleSkillRatingsRepository roleSkillRatingsRepository){
this.roleSkillRatingsRepository = roleSkillRatingsRepository;
}
@ResponseBody
public List<Employee> getAllemployees() {
System.out.println(employeeRepository.findAll());
return employeeRepository.findAll();
}
@ResponseBody
public Map<String,Integer> getRoleSkills() {
return null;
}
角色存储库
@Repository
public interface RoleRepository extends CrudRepository<Role, Integer> {
List<Role> findAll();
//something I found online but unsure how to apply this to my situation
@Query("select p from Person AS p"
+ " ,Name AS n"
+ " where p.forename = n.forename "
+ " and p.surname = n.surname"
+ " and n = :name")
String [] findByName(@Param("name") Name name);
}