gpt4 book ai didi

mysql - 使用springboot从mysql表中获取id并与url连接

转载 作者:行者123 更新时间:2023-11-29 21:22:36 25 4
gpt4 key购买 nike

我已将下面的 id 硬编码为 1,但我需要从 EMPLOYEE 数据库的员工详细信息表中获取 id

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=? ");
}

我如何通过 Spring Boot Java 配置来实现这一点?

最佳答案

无论我从你的问题中了解到什么,我都有一个解决方案在 EmployeeDAO
中编写一个员工查询这里 Employee 是所有 getter setter 方法的实体类

public Employee getByUserId(Integer userId) {

//return your query for userId here

}

然后在您必须使用员工 ID 的用户类中调用此类

@Autowired
EmployeeDAO employeeDAO;

public void addViewControllers(ViewControllerRegistry registry) {

Employee employee = employeeDAO.getByUserId(//pass your user id here)
id = employee.getId();

registry.addViewController("/home").setViewName("home");
registry.addRedirectViewController("/", "/applyleave/"+ id);
}

这样就可以在这里使用employeeId了。

关于mysql - 使用springboot从mysql表中获取id并与url连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35651156/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com