整合spring与mybatis及相关配置
精简版的, 直说重要的部分
目录结构如下:
6.简单查询@Repository("demoDao")public class DemoDaoImpl extends SqlSessionDaoSupport implements DemoDao{public User getUserById(int id) {return (User) this.getSqlSession().selectOne("A.selectUserById",1);}}A就是User.xml中的namespace, selectUserById就是<select.../>中的idA.selectUserById就唯一确定了这条sql语句select * from users where id=#{id}1就是传入的参数,执行之后log4j会在控制台输出如下:2013-08-28 17:19:16,896 [http-8888-2] DEBUG [java.sql.PreparedStatement] - ==> Executing: select * from users where id=? 2013-08-28 17:19:16,897 [http-8888-2] DEBUG [java.sql.PreparedStatement] - ==> Parameters: 1(Integer)其中的Parameters:1(Integer)是显示传入的参数