这个怎么把从数据库取得数据,年月日提取出来呢?或者时分秒,怎么提取呢?
package com.testmysql.one.testonDao; import com.testmysql.one.testonentity.Userone; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Repository; import javax.annotation.Resource; import java.util.List; import java.util.Map; @Repository public class UserDao { @Resource private JdbcTemplate jdbcTemplate; public List<Map<String,Object>> useronet(String username){ String sql="SELECT * FROM test_two WHERE username=?"; List<Map<String,Object>> maps=jdbcTemplate.queryForList(sql,new Object[]{username}); return maps; } } import com.testmysql.one.testonDao.UserDao; import com.testmysql.one.testonentity.Userone; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import java.util.List; public class Test_Two { public static void main(String[] args) { ApplicationContext context=new ClassPathXmlApplicationContext("classpath:applicationtext.xml"); UserDao userDao=context.getBean("userDao",UserDao.class); List userone= userDao.useronet("肖点和"); for (int i=0;i<userone.size();i++){ System.out.println(userone.get(i)); } } }
{username=肖点和, datatime=2022-08-01T07:36}
{username=肖点和, datatime=2022-08-02T07:43}
{username=肖点和, datatime=2022-08-02T16:45}
{username=肖点和, datatime=2022-08-03T07:37}
{username=肖点和, datatime=2022-08-03T17:02}
{username=肖点和, datatime=2022-08-04T07:48}
{username=肖点和, datatime=2022-08-04T17:06}
{username=肖点和, datatime=2022-08-05T07:43}
{username=肖点和, datatime=2022-08-05T17:00}
{username=肖点和, datatime=2022-08-06T07:37}
{username=肖点和, datatime=2022-08-06T17:02}
{username=肖点和, datatime=2022-08-07T07:41}
{username=肖点和, datatime=2022-08-07T17:01}
{username=肖点和, datatime=2022-08-08T07:44}
{username=肖点和, datatime=2022-08-08T07:56}
{username=肖点和, datatime=2022-08-08T17:00}
{username=肖点和, datatime=2022-08-09T06:44}
{username=肖点和, datatime=2022-08-09T17:00}
{username=肖点和, datatime=2022-08-10T07:44}
{username=肖点和, datatime=2022-08-10T16:59}
{username=肖点和, datatime=2022-08-11T07:42}
{username=肖点和, datatime=2022-08-11T12:01}
{username=肖点和, datatime=2022-08-12T07:44}
{username=肖点和, datatime=2022-08-12T17:00}
{username=肖点和, datatime=2022-08-13T07:52}
{username=肖点和, datatime=2022-08-13T17:00}
{username=肖点和, datatime=2022-08-14T07:39}
{username=肖点和, datatime=2022-08-14T17:00}
{username=肖点和, datatime=2022-08-15T07:52}
{username=肖点和, datatime=2022-08-15T17:00}
{username=肖点和, datatime=2022-08-16T07:48}
{username=肖点和, datatime=2022-08-16T17:07}
{username=肖点和, datatime=2022-08-17T07:43}
{username=肖点和, datatime=2022-08-17T17:00}
{username=肖点和, datatime=2022-08-18T05:57}
{username=肖点和, datatime=2022-08-18T17:00}
{username=肖点和, datatime=2022-08-19T07:48}
{username=肖点和, datatime=2022-08-19T15:07}
{username=肖点和, datatime=2022-08-19T15:38}
{username=肖点和, datatime=2022-08-19T17:01}
{username=肖点和, datatime=2022-08-20T06:51}
{username=肖点和, datatime=2022-08-20T17:06}
{username=肖点和, datatime=2022-08-21T07:46}
{username=肖点和, datatime=2022-08-21T07:49}
{username=肖点和, datatime=2022-08-21T17:00}
{username=肖点和, datatime=2022-08-22T07:41}
{username=肖点和, datatime=2022-08-22T17:01}
{username=肖点和, datatime=2022-08-23T07:52}
{username=肖点和, datatime=2022-08-23T17:01}
{username=肖点和, datatime=2022-08-24T07:45}
{username=肖点和, datatime=2022-08-24T17:09}
正在回答
同学你好,可以将日期属性设置为LocalDateTime类型。LocalDateTime类型对应MySql中的Timestamp类型,是包含时分秒的类型。
老师结合课程源码,给同学提供一些操作的代码,代码如下:
@Test public void testFindById(){ Employee employee = employeeDao.findById(3308); //获取入职时间 LocalDateTime hiredate = employee.getHiredate(); //获取年份 int year = hiredate.getYear(); //获取月份 int month = hiredate.getMonth().getValue(); //获取日期 int day = hiredate.getDayOfMonth(); //获取时 int hour = hiredate.getHour(); //获取分 int minute = hiredate.getMinute(); //获取秒 int second = hiredate.getSecond(); }
祝学习愉快~
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星