我已經硬編碼了下面的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從不同的表 –