mybatis按时间查询oracle数据

来源:互联网 发布:最新网络语 编辑:程序博客网 时间:2024/06/06 03:26

mybatis配置按时间查询oracle数据

1.mybatis中查询sql配置

<select id="findArticleByid" parameterType="com.hehe.ParaBean" resultType="com.hehe.bean.Page">     select * from table p where p.time &lt;= #{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;}



0 0
原创粉丝点击