您的位置:首页 > 数据库 > Oracle

mybatis按时间查询oracle数据

2015-07-22 15:34 483 查看
mybatis配置按时间查询oracle数据

1.mybatis中查询sql配置

<select id="findArticleByid" parameterType="com.hehe.ParaBean" resultType="com.hehe.bean.Page">
select * from table p where p.time <;= #{time}
and p.id = #{id}
</select>


2.java中调用

public void test(){
SqlSessionFactory sqlSessionFactory = DBSqlSessionFactory.getInstance("DBname");
SqlSession sqlSession = sqlSessionFactory.openSession();
ParaBean paraBean = new ParaBean();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
Date date = format.parse("2011-01-01 00:00:00");
paraBean.setId(111840);
paraBean.setTime(date);
} catch (ParseException e) {
e.printStackTrace();
}
List<Page> list = sqlSession.selectList("com.hehe.mapper.PageMapper.findArticleById",paraBean);
System.out.println(list.size());
sqlSession.close();
}


3.paraBean查询参数Bean

public class ParaBean {
private int id;
private Date time;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: