Created
July 23, 2016 04:55
-
-
Save leonlee/fb264eb24078f7df5abd511c018e15d9 to your computer and use it in GitHub Desktop.
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
public abstract class BaseDAO { | |
private static final Logger L = LoggerFactory.getLogger(BaseDAO.class); | |
@Autowired | |
protected JdbcTemplate template; | |
@PostConstruct | |
public void afterInit() { | |
L.info("base dao"); | |
if (template == null) { | |
L.warn("got null jdbc template"); | |
} else { | |
L.info("got jdbc template {}", template.getDataSource().toString()); | |
} | |
} | |
} | |
@Component | |
public class UserDAO extends BaseDAO { | |
private static final Logger L = LoggerFactory.getLogger(UserDAO.class); | |
public void test() { | |
Map data = template.queryForMap("select * from account limit 1"); | |
for (Object o : data.entrySet()) { | |
Map.Entry entry = (Map.Entry) o; | |
L.info("got entry {} > {}", entry.getKey(), entry.getValue()); | |
} | |
} | |
} | |
@Service | |
public class UserService implements IUserService { | |
@Autowired | |
private UserDAO userDAO; | |
@PostConstruct | |
public void test() { | |
userDAO.test(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment