Last active
August 29, 2015 14:01
-
-
Save subchen/0ec61440c072e0d3fb6b to your computer and use it in GitHub Desktop.
demo for jetbrick-webmvc + orm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@IocBean("jetbrick.dao.orm.JdbcHelper") | |
public class DAOHelperFactory implements IocFactory<JdbcHelper> { | |
@Inject | |
private DataSource dataSource; | |
public JdbcHelper getObject() { | |
return new JdbcHelper(dataSource); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@IocBean("javax.sql.DataSource") | |
public class DruidDataSourceFactory implements IocFactory<DataSource> { | |
@Config("jdbc.url") | |
private String url; | |
@Config("jdbc.username") | |
private String username; | |
@Config("jdbc.password") | |
private String password; | |
@Override | |
public DataSource getObject() { | |
DruidDataSource ds = new DruidDataSource(); | |
ds.setUrl(url); | |
ds.setUsername(username); | |
ds.setPassword(password); | |
return ds; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jdbc.url = jdbc:mysql://127.0.0.1:3306/XXX | |
jdbc.username = root | |
jdbc.password = root | |
$dataSource = com.alibaba.druid.pool.DruidDataSource | |
$dataSource.url = jdbc:mysql://127.0.0.1:3306/XXX | |
$dataSource.username = root | |
$dataSource.password = root |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Controller | |
public class PassportController { | |
@Inject | |
private PassportDAO passportDAO; | |
@Action("/passport/check") | |
public JSONAware checkUserPassword( | |
@RequestParam("name") String name, | |
@RequestParam("pass") String pass | |
) { | |
boolean succ = passportDAO.checkUserPassword(name, pass); | |
return JSON.wrap(succ); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@IocBean | |
public class PassportDAO { | |
@Inject | |
private JdbcHelper jdbc; | |
public boolean checkUserPassword(String name, String pass) { | |
User user = jdbc.queryAsObject(User.class, "select * from User where name=?", name); | |
if (user != null) { | |
return pass.equals(user.getPassword()); | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment