我已经硬编码了下面的ID为1串连,但我需要从EMPLOYEE数据库的employeedetails表中提取ID以ID从MySQL表表springboot与URL
int id=1; //This id needs to come from table from column id
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/home").setViewName("home");
registry.addRedirectViewController("/", "/applyleave/"+ id);
}
@Autowired
public DataSource dataSource() {
BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
dataSource.setUrl("jdbc:mysql://localhost:3306/EMPLOYEE");
dataSource.setUsername("root");
dataSource.setPassword("password");
return dataSource;
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.jdbcAuthentication().dataSource(dataSource()).usersByUsernameQuery("select user_id, password, loginstatus from employeedetails where user_id=? ").authoritiesByUsernameQuery("select user_id, role from employeedetails where user_id=? ");
}
我怎样才能做到这一点与春季启动java配置?
在employeee中写入一个查询方法。其中将查找员工表中的所有条目。然后在上面的代码中调用该方法。然后设置为employee.getid(ID),并通过它在任何你想要 –
我在DAO这个代码,但我无法从主要的Java文件调用此方法:我如何可以调用上面的Java代码 这种方法'公Integer getidforuserId(String userId){ \t \t return(Integer)entityManager.createQuery(“从雇员中选择id,其中userId是:userId”).setParameter(“userId”,userId).getSingleResult(); \t}' – Vikram
我无法正常得到你的代码,但如果你想那么我可以分享我如何使用这样的ID从不同的表 –