Mybatis获取当前数据库时间

时间:2022-09-23 08:43:23

一、Oracle时间

Dao接口:

/**
* 获取当前数据库时间
* @return
* @throws CommonException
*/
Date getCurrentDates();

Mapper:

  <select id="getCurrentDates" resultType="java.util.Date">
select sysdate from dual
</select>

测试类:

/**
* @version: V1.0
* @author: fendo
* @className: Controller
* @packageName: test
* @description: Controller测试
* @data: 2018-01-05 10:54
**/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"classpath:spring.xml"})
public class Controller {

@Autowired
private HealthConsultationMapper healthConsultationMapper;


@Test
public void TestA() throws CommonException {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date des = healthConsultationMapper.getCurrentDates();
System.out.println(format.format(des));
}
}
输出为:

2018-01-05 13:53:42