Mybatis获取当前数据库时间

一、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
本站公众号
   欢迎关注本站公众号,获取更多程序园信息
开发小院