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 ed77f5a..55847c8 100644
Binary files a/sqlite.db and b/sqlite.db differ
diff --git a/src/main/java/com/louzin/structure/dao/HostDao.java b/src/main/java/com/louzin/structure/dao/HostDao.java
new file mode 100644
index 0000000..499d401
--- /dev/null
+++ b/src/main/java/com/louzin/structure/dao/HostDao.java
@@ -0,0 +1,9 @@
+package com.louzin.structure.dao;
+
+import com.louzin.structure.pojo.Host;
+import java.util.List;
+
+public interface HostDao {
+ List 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 @@
+