diff --git a/WebProject/src/main/java/com/example/webproject/com/Control/control.java b/WebProject/src/main/java/com/example/webproject/com/Control/control.java index 224ae82..ed5bc35 100644 --- a/WebProject/src/main/java/com/example/webproject/com/Control/control.java +++ b/WebProject/src/main/java/com/example/webproject/com/Control/control.java @@ -3,6 +3,7 @@ package com.example.webproject.com.Control; import com.example.webproject.com.Mapper.account_operator; import com.example.webproject.com.Mapper.user_data_operator; import com.example.webproject.com.Pojo.account; +import com.example.webproject.com.Pojo.user_data; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; @@ -12,6 +13,10 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.ModelAndView; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.List; import java.util.Map; @Controller @@ -36,7 +41,7 @@ public class control { //这里要开始编写我们的对于账号上面的处理了 @RequestMapping("/postProcessorRegistration") - public ModelAndView postProcessorRegistration(@RequestParam Map map){ + public ModelAndView postProcessorRegistration(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse,@RequestParam Map map){ System.out.println("postProcessorRegistration"); //这里我们是进行注册操作 //我们先去数据库里面查一下,有没有这个账号 @@ -62,18 +67,22 @@ public class control { modelAndView.setViewName("Login"); modelAndView.addObject("isHaveAccount","当前账号已有"); } + + return modelAndView; } //这里要开始编写我们的对于账号上面的处理了 @RequestMapping("/postProcessorLogin") - @ResponseBody - public ModelAndView postProcessorLogin(Map map){ +// @ResponseBody + public ModelAndView postProcessorLogin(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse,@RequestParam Map map){ System.out.println("postProcessorLogin"); ModelAndView modelAndView = new ModelAndView(); //首先我们先从map中拿到 account和 password String account = (String)map.get("account"); String password = (String)map.get("password"); + System.out.println("account=="+account); + System.out.println("password=="+ password); account one = account_operator.findOne(account); if(one == null){ System.out.println("还没有账号,请注册一个"); @@ -81,9 +90,17 @@ public class control { modelAndView.addObject("isHaveAccount","还没有账号,注册一个"); modelAndView.setViewName("Login"); }else{ - if((one.getTxl_password() == password)){ + if((one.getTxl_password().equals(password))){ System.out.println("密码正确,登入成功"); - modelAndView.setViewName("data_operator"); +// modelAndView.setViewName("data_operator"); + modelAndView.setViewName("redirect:data"); + //在这里要进行coockie的设置,在response 里面进行操作 + //我们要在登入界面进行操作,一旦登入操作成功,我们就在这里进行cookie设置 + //将cookie设置过去 + Cookie account_cookie = new Cookie("account",account); + Cookie password_cookie = new Cookie("password",password); + httpServletResponse.addCookie(account_cookie); + httpServletResponse.addCookie(password_cookie); }else{ System.out.println("密码错误,登入失败"); modelAndView.setViewName("Login"); @@ -91,4 +108,143 @@ public class control { } return modelAndView; } + + + @RequestMapping("data") + public ModelAndView data_operator(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse){ + //获得所有的cookie + Cookie[]cookies = httpServletRequest.getCookies(); + //为cookie设置过期时间 + String account = ""; + for (Cookie cookie : cookies) { + //当我们设置了cookie之后就只能通过https进行传输了,不会在http里面进行传输 + // cookie.setSecure(true); + //设置为1星期的过期时间 +// cookie.setMaxAge(7*24*60*60); + System.out.println(cookie.getName() + "==" + cookie.getValue()); + if("account".equals(cookie.getName())){ + account = cookie.getValue(); + } + } + //我们就可以设置cookie,当我们发现cookie里面已经存在了账户,之后就直接显示当前的这个用户的数据 + ModelAndView modelAndView = new ModelAndView(); + //这里我们后面肯定是要根据我们当前的一个用户,进行操作的 + //我们根据页面上面的显示来进行操作 + //页面上面有什么么,我们就要进行什么操作 + //就显示一个列表,通过一个参数显示每页 要显示多少的数据,在显示出来总数据的条数 + //在每条数据的后面我们就显示,一个删除的按钮,修改, + + + List all = user_data_operator.findOne(account); + modelAndView.addObject("user_data",all); + modelAndView.setViewName("data_operator"); + return modelAndView; + } + + @RequestMapping("add_user_data") + public ModelAndView add_user_data(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse,@RequestParam Map map){ + + System.out.println("add_user_data"); + ModelAndView modelAndView = new ModelAndView(); + Cookie[]cookies = httpServletRequest.getCookies(); + //为cookie设置过期时间 + String account = ""; + for (Cookie cookie : cookies) { + //当我们设置了cookie之后就只能通过https进行传输了,不会在http里面进行传输 + // cookie.setSecure(true); + //设置为1星期的过期时间 +// cookie.setMaxAge(7*24*60*60); + System.out.println(cookie.getName() + "==" + cookie.getValue()); + if("account".equals(cookie.getName())){ + account = cookie.getValue(); + } + } + + //获取数据 + String name = map.get("name"); +// String sex = map.get("sex"); + String contact_phone_number = map.get("contact_phone_number"); + if(name != null || contact_phone_number != null){ + //插入操作 + user_data_operator.insertOne(account,name,contact_phone_number); + modelAndView.addObject("message","插入成功"); + System.out.println("here"); + + //modelAndView.setViewName("redirect:data"); + }else{ + modelAndView.setViewName("add_user_data"); + } + return modelAndView; + } + @RequestMapping("delete_user_data") + public ModelAndView delete_user_data(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse,@RequestParam Map map){ + + + System.out.println("delete_user_data"); + ModelAndView modelAndView = new ModelAndView(); + Cookie[]cookies = httpServletRequest.getCookies(); + //为cookie设置过期时间 + String account = ""; + for (Cookie cookie : cookies) { + //当我们设置了cookie之后就只能通过https进行传输了,不会在http里面进行传输 + // cookie.setSecure(true); + //设置为1星期的过期时间 +// cookie.setMaxAge(7*24*60*60); + System.out.println(cookie.getName() + "==" + cookie.getValue()); + if("account".equals(cookie.getName())){ + account = cookie.getValue(); + } + } + + String name = map.get("name"); + if(name != null ){ + //删除操作 +// user_data_operator + user_data_operator.deleteOne(account,name); + modelAndView.addObject("message","删除成功"); + System.out.println("here"); + + // modelAndView.setViewName("redirect:data") + }else{ + modelAndView.setViewName("delete_user_data"); + } + return modelAndView; + } + @RequestMapping("find_user_data") + public ModelAndView find_user_data(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse,@RequestParam Map map){ + + + System.out.println("find_user_data"); + ModelAndView modelAndView = new ModelAndView(); + Cookie[]cookies = httpServletRequest.getCookies(); + //为cookie设置过期时间 + String account = ""; + for (Cookie cookie : cookies) { + //当我们设置了cookie之后就只能通过https进行传输了,不会在http里面进行传输 + // cookie.setSecure(true); + //设置为1星期的过期时间 +// cookie.setMaxAge(7*24*60*60); + System.out.println(cookie.getName() + "==" + cookie.getValue()); + if("account".equals(cookie.getName())){ + account = cookie.getValue(); + } + } + String name = map.get("name"); + + //查找完成后英爱回显数据 + if(name != null ){ + //查找操作 + List oneByName = user_data_operator.findOneByName(account, name); + modelAndView.addObject("message","查找完成"); + modelAndView.addObject("user_data",oneByName); + System.out.println("here"); + //modelAndView.setViewName("redirect:data"); + }else{ + modelAndView.setViewName("find_user_data"); + } + + return modelAndView; + } + + } diff --git a/WebProject/src/main/java/com/example/webproject/com/Mapper/user_data_operator.java b/WebProject/src/main/java/com/example/webproject/com/Mapper/user_data_operator.java index 5277727..ef73cc5 100644 --- a/WebProject/src/main/java/com/example/webproject/com/Mapper/user_data_operator.java +++ b/WebProject/src/main/java/com/example/webproject/com/Mapper/user_data_operator.java @@ -10,4 +10,13 @@ import java.util.List; public interface user_data_operator { // @Select("select * from user_data_table") public List findAll(); + + public List findOne(String txl_account); + + public List findOneByName(String txl_account,String txl_name); + + public Integer deleteOne(String txl_account,String txl_name); + + public Integer insertOne(String account,String name,String contact_phone_number); + } diff --git a/WebProject/src/main/resources/MyBatis/account_operator.xml b/WebProject/src/main/resources/MyBatis/account_operator.xml index 6d45404..2309bbc 100644 --- a/WebProject/src/main/resources/MyBatis/account_operator.xml +++ b/WebProject/src/main/resources/MyBatis/account_operator.xml @@ -17,7 +17,10 @@ select * from account_table where txl_account=#{txl_account} - + + + + insert into account_table values( #{account.txl_account}, #{account.txl_password}) diff --git a/WebProject/src/main/resources/MyBatis/user_data_operator.xml b/WebProject/src/main/resources/MyBatis/user_data_operator.xml index e533a60..ea9942d 100644 --- a/WebProject/src/main/resources/MyBatis/user_data_operator.xml +++ b/WebProject/src/main/resources/MyBatis/user_data_operator.xml @@ -15,4 +15,23 @@ select * from user_data_table + + + + + + + + delete from user_data_table where txl_account=#{txl_account} and txl_name=#{txl_name} + + + + insert into user_data_table values(#{account},#{name},#{contact_phone_number},'','','','','','','','') + + + \ No newline at end of file diff --git a/WebProject/src/main/resources/static/bg2.jpg b/WebProject/src/main/resources/static/bg2.jpg new file mode 100644 index 0000000..091f9eb Binary files /dev/null and b/WebProject/src/main/resources/static/bg2.jpg differ diff --git a/WebProject/src/main/resources/templates/Login.html b/WebProject/src/main/resources/templates/Login.html index 9d9a8a2..20fb5d8 100644 --- a/WebProject/src/main/resources/templates/Login.html +++ b/WebProject/src/main/resources/templates/Login.html @@ -129,7 +129,7 @@ #box{ width: 1000px; height: 500px; - background-color: aqua; + background-color: ivory; margin-top: 5%; border: 1px solid transparent; display: flex; @@ -237,11 +237,13 @@ if(isHaveAccount != null){ if(isHaveAccount === "当前账号已有"){ p.innerText = '注册'; + console.log("没有账号") var login = document.querySelector("#login"); login.style.opacity=0; login.zIndex='0'; + var context = document.querySelector("#context"); context.style.transform='translateX(200px)'; p.innerText = '登入'; @@ -253,6 +255,7 @@ //要输出已有 var secondP = document.querySelector("#context p:first-child"); secondP.innerText = isHaveAccount; + secondP.style.color="red"; }else if(isHaveAccount ===''){ console.log("没有账号") diff --git a/WebProject/src/main/resources/templates/add_user_data.html b/WebProject/src/main/resources/templates/add_user_data.html new file mode 100644 index 0000000..77a7058 --- /dev/null +++ b/WebProject/src/main/resources/templates/add_user_data.html @@ -0,0 +1,148 @@ + + + + + + + + 添加联系人 + + + + +
+
+

添加联系人

+
+
+
+ + + + + + + + + + + + + + + + + + + + +
+
+ +
+

+
+ +
+ + + + + + + \ No newline at end of file diff --git a/WebProject/src/main/resources/templates/data_operator.html b/WebProject/src/main/resources/templates/data_operator.html index 566549b..42d71da 100644 --- a/WebProject/src/main/resources/templates/data_operator.html +++ b/WebProject/src/main/resources/templates/data_operator.html @@ -1,10 +1,206 @@ + Title + + + + + + + + + + +
+ +
+ + + +
+ + + + +
+ + + + + + + + + + + + + + + + + +
+
+
+ \ No newline at end of file diff --git a/WebProject/src/main/resources/templates/delete_user_data.html b/WebProject/src/main/resources/templates/delete_user_data.html new file mode 100644 index 0000000..7176fa4 --- /dev/null +++ b/WebProject/src/main/resources/templates/delete_user_data.html @@ -0,0 +1,120 @@ + + + + + + + + 查找联系人 + + + + +
+
+

删除联系人

+
+
+ + +
+

+ +
+ + + + + \ No newline at end of file diff --git a/WebProject/src/main/resources/templates/find_user_data.html b/WebProject/src/main/resources/templates/find_user_data.html new file mode 100644 index 0000000..e62b8b9 --- /dev/null +++ b/WebProject/src/main/resources/templates/find_user_data.html @@ -0,0 +1,120 @@ + + + + + + + + 查找联系人 + + + + +
+
+

查找联系人

+
+
+ + +
+

+ +
+ + + + + \ No newline at end of file