From 0a828a81234aa005c2f0645b8d758b60fd64c5b0 Mon Sep 17 00:00:00 2001 From: louzin <294098546@qq.com> Date: Tue, 14 Mar 2023 20:51:44 +0800 Subject: [PATCH] ChangeLog --- pom.xml | 14 ++++ sqlite.db | Bin 24576 -> 24576 bytes .../java/com/louzin/structure/dao/HostDao.java | 9 +++ .../com/louzin/structure/dao/impl/HostDaoImpl.java | 36 ++++++++++ src/main/java/com/louzin/structure/pojo/Host.java | 80 ++++++++++++++++++++- src/main/java/com/louzin/structure/util/test.java | 19 ++++- src/main/resources/db.properties | 3 +- src/main/resources/mapper/HostMapper.xml | 13 ++++ src/main/resources/mybatis-config.xml | 1 + 9 files changed, 169 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/louzin/structure/dao/HostDao.java create mode 100644 src/main/java/com/louzin/structure/dao/impl/HostDaoImpl.java create mode 100644 src/main/resources/mapper/HostMapper.xml diff --git a/pom.xml b/pom.xml index 3c9408f..9c5f2d4 100644 --- a/pom.xml +++ b/pom.xml @@ -77,11 +77,25 @@ RELEASE compile + org.springframework.boot spring-boot-devtools 2.5.14 + + + + org.mybatis + mybatis-typehandlers-jsr310 + 1.0.1 + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + 2.9.2 + + diff --git a/sqlite.db b/sqlite.db index ed77f5a6f5fd1d0b45e5ca568a5a70e506cc1ebe..55847c8c95049fd74f8471f1f6cad6fbf044512f 100644 GIT binary patch delta 140 zcmZoTz}Rqrae}m!R;?{gjDD+*E~>#FEs_QG9C*SxzzVp8_gBz%O9J l$j%@uDQV1VXryPTXQVgzLA(r?xs|C2W7`9nzEz6?1OSC1BEtXx delta 158 zcmZoTz}Rqrae}mHOS$(Y%>F*_#Cg zzH(2_=J_PX$RMt(%h;@2l9-g!n9s&8E-w${O-|>1zB!6-jUme;2L4At)kpY^Of@AX zjSVf0G?>^JBt^xIbMi~8WEj~P`1$#b6B84S42+C*4UBaSO%x0btW3 selectAll(); + Integer update(Host person); +} diff --git a/src/main/java/com/louzin/structure/dao/impl/HostDaoImpl.java b/src/main/java/com/louzin/structure/dao/impl/HostDaoImpl.java new file mode 100644 index 0000000..af66ed8 --- /dev/null +++ b/src/main/java/com/louzin/structure/dao/impl/HostDaoImpl.java @@ -0,0 +1,36 @@ +package com.louzin.structure.dao.impl; + +import com.louzin.structure.dao.HostDao; +import com.louzin.structure.pojo.Host; +import com.louzin.structure.util.MyBatisUtil; +import org.apache.ibatis.session.SqlSession; + +import java.util.List; + +public class HostDaoImpl implements HostDao { + @Override + public List selectAll() { + List list=null; + try(SqlSession session= MyBatisUtil.getSqlSession()) { + HostDao mapper =session.getMapper(HostDao.class); + list=mapper.selectAll(); + }catch (Exception e){ + System.out.println(e); + } + return list; + } + + @Override + public Integer update(Host host) { + try(SqlSession session=MyBatisUtil.getSqlSession()){ + HostDao mapper=session.getMapper(HostDao.class); + Integer result=mapper.update(host); + session.commit(); + return result; + }catch (Exception e){ + System.out.println(e); + } + return 0; + } + +} diff --git a/src/main/java/com/louzin/structure/pojo/Host.java b/src/main/java/com/louzin/structure/pojo/Host.java index 5544144..22420e5 100644 --- a/src/main/java/com/louzin/structure/pojo/Host.java +++ b/src/main/java/com/louzin/structure/pojo/Host.java @@ -1,10 +1,86 @@ package com.louzin.structure.pojo; -import java.sql.Date; +import com.fasterxml.jackson.annotation.JsonFormat; + +import java.util.Date; public class Host { + private Integer id; private String username; private String password; private String host; - private Date date; + @JsonFormat(pattern = "yyyy-MM-dd HH-mm-ss") + private Date ctime; + @JsonFormat(pattern = "yyyy-MM-dd HH-mm-ss") + private Date utime; + + public Date getUtime() { + return utime; + } + + public void setUtime(Date utime) { + this.utime = utime; + } + + + + public Host(){} + + @Override + public String toString() { + return "Host{" + + "id=" + id + + ", username='" + username + '\'' + + ", password='" + password + '\'' + + ", host='" + host + '\'' + + ", ctime=" + ctime + + ", utime=" + utime + + '}'; + } + + public Host(String username, String password, String host) { + this.username = username; + this.password = password; + this.host = host; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getHost() { + return host; + } + + public void setHost(String host) { + this.host = host; + } + + public Date getCtime() { + return ctime; + } + + public void setCtime(Date ctime) { + this.ctime = ctime; + } } diff --git a/src/main/java/com/louzin/structure/util/test.java b/src/main/java/com/louzin/structure/util/test.java index 271d24b..9f1c56c 100644 --- a/src/main/java/com/louzin/structure/util/test.java +++ b/src/main/java/com/louzin/structure/util/test.java @@ -1,14 +1,17 @@ package com.louzin.structure.util; +import com.louzin.structure.dao.impl.HostDaoImpl; import com.louzin.structure.dao.impl.PersonDaoImpl; import com.louzin.structure.dao.impl.UserDaoImpl; +import com.louzin.structure.pojo.Host; import com.louzin.structure.pojo.User; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import org.testng.annotations.Test; -import java.sql.Date; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.List; @Controller @@ -19,7 +22,6 @@ public class test { public static void main(String[] args) { PersonDaoImpl personDaoImpl = new PersonDaoImpl(); personDaoImpl.selectAll(); - } @Test @PostMapping("/post") @@ -62,6 +64,17 @@ public class test { } @Test public void sqldate(){ - System.out.println(new java.sql.Date(new java.util.Date().getTime())); +// System.out.println(new java.sql.Date(new java.util.Date().getTime())); + System.out.println(new HostDaoImpl().selectAll()); + } + @Test + public void testInserthosttable(){ + Host host = new Host("louzin","123456","12.1.2.2"); + host.setId(1); + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); +// host.setUtime(new java.util.Date().getTime()); + //无法将date解析成timestamp 待解决 + System.out.println(new HostDaoImpl().update(host)); + } } diff --git a/src/main/resources/db.properties b/src/main/resources/db.properties index b698b8d..601a76f 100644 --- a/src/main/resources/db.properties +++ b/src/main/resources/db.properties @@ -1,2 +1,3 @@ driver=org.sqlite.JDBC -url=jdbc:sqlite:sqlite.db \ No newline at end of file +url=jdbc:sqlite:sqlite.db +date_string_format=yyyy-MM-dd HH:mm:ss \ No newline at end of file diff --git a/src/main/resources/mapper/HostMapper.xml b/src/main/resources/mapper/HostMapper.xml new file mode 100644 index 0000000..d12dcf0 --- /dev/null +++ b/src/main/resources/mapper/HostMapper.xml @@ -0,0 +1,13 @@ + + + + + + + update hosttable set host=#{host},username = #{username}, password = #{password},utime=#{utime} where id = #{id} + + \ No newline at end of file diff --git a/src/main/resources/mybatis-config.xml b/src/main/resources/mybatis-config.xml index 4376620..4041a1f 100644 --- a/src/main/resources/mybatis-config.xml +++ b/src/main/resources/mybatis-config.xml @@ -31,5 +31,6 @@ +