From 375439d2c18b5a6116da13a1da8d83a2e41ff920 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=BA=E5=BF=97=E8=B1=AA?= <3087861069@qq.com> Date: Fri, 22 Dec 2023 10:48:43 +0800 Subject: [PATCH] code --- 404.html | 11 ++ Login.html | 272 +++++++++++++++++++++++++++++++++++++ ServletInitializer.java | 13 ++ WebProjectApplication.java | 13 ++ account.java | 23 ++++ account_operator.java | 23 ++++ account_operator.xml | 34 +++++ add_user_data.html | 148 ++++++++++++++++++++ application.yml | 16 +++ control.java | 256 ++++++++++++++++++++++++++++++++++ data_operator.html | 206 ++++++++++++++++++++++++++++ delete_user_data.html | 120 ++++++++++++++++ error.html | 10 ++ find_user_data.html | 120 ++++++++++++++++ user_data.java | 40 ++++++ user_data_operator.java | 22 +++ user_data_operator.xml | 37 +++++ 17 files changed, 1364 insertions(+) create mode 100644 404.html create mode 100644 Login.html create mode 100644 ServletInitializer.java create mode 100644 WebProjectApplication.java create mode 100644 account.java create mode 100644 account_operator.java create mode 100644 account_operator.xml create mode 100644 add_user_data.html create mode 100644 application.yml create mode 100644 control.java create mode 100644 data_operator.html create mode 100644 delete_user_data.html create mode 100644 error.html create mode 100644 find_user_data.html create mode 100644 user_data.java create mode 100644 user_data_operator.java create mode 100644 user_data_operator.xml diff --git a/404.html b/404.html new file mode 100644 index 0000000..d4b689c --- /dev/null +++ b/404.html @@ -0,0 +1,11 @@ + + + + + Title + + + +This is 404 page + + \ No newline at end of file diff --git a/Login.html b/Login.html new file mode 100644 index 0000000..20fb5d8 --- /dev/null +++ b/Login.html @@ -0,0 +1,272 @@ + + + + + + 通讯录登入界面 + + + + + +
+
+

+

注册

+
+
+ +
+ 账号 : + +
+ +
+ 密码 : + +
+ +
+
+ +
+ +
+ 账号 : + +
+ +
+ 密码 : + +
+ +
+ + +
+ + + + + + + \ No newline at end of file diff --git a/ServletInitializer.java b/ServletInitializer.java new file mode 100644 index 0000000..907edd2 --- /dev/null +++ b/ServletInitializer.java @@ -0,0 +1,13 @@ +package com.example.webproject; + +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; + +public class ServletInitializer extends SpringBootServletInitializer { + + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { + return application.sources(WebProjectApplication.class); + } + +} diff --git a/WebProjectApplication.java b/WebProjectApplication.java new file mode 100644 index 0000000..c6602a0 --- /dev/null +++ b/WebProjectApplication.java @@ -0,0 +1,13 @@ +package com.example.webproject; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class WebProjectApplication { + + public static void main(String[] args) { + SpringApplication.run(WebProjectApplication.class, args); + } + +} diff --git a/account.java b/account.java new file mode 100644 index 0000000..533b0af --- /dev/null +++ b/account.java @@ -0,0 +1,23 @@ +package com.example.webproject.com.Pojo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class account { + private String txl_account; + private String txl_password; + + @Override + public String toString() { + return "account{" + + "txl_account='" + txl_account + '\'' + + ", txl_password='" + txl_password + '\'' + + '}'; + } + + +} diff --git a/account_operator.java b/account_operator.java new file mode 100644 index 0000000..638e536 --- /dev/null +++ b/account_operator.java @@ -0,0 +1,23 @@ +package com.example.webproject.com.Mapper; + +import com.example.webproject.com.Pojo.account; +import org.apache.ibatis.annotations.*; + +import java.util.List; + +@Mapper +public interface account_operator { + //查出所有的记录 +// @Select("select * from account_table") + public List findAll(); + +// @Select("select * from account_table where txl_account=#{account}") + public account findOne( @Param("txl_account") String txl_account); + + //新增加一条记录 +// @Insert("insert into account_table values(txl_account=#{account},txl_password=#{password})") + public Integer insertOne(@Param("account") account account); +// //删除一条记录 +//// @Delete("delete from account_table where txl_account=#{account}") + public Integer deleteOne(String txl_account); +} diff --git a/account_operator.xml b/account_operator.xml new file mode 100644 index 0000000..2309bbc --- /dev/null +++ b/account_operator.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + insert into account_table values( #{account.txl_account}, #{account.txl_password}) + + + + + delete from account_table where txl_account=#{txl_account} + + + diff --git a/add_user_data.html b/add_user_data.html new file mode 100644 index 0000000..64e094f --- /dev/null +++ b/add_user_data.html @@ -0,0 +1,148 @@ + + + + + + + + 添加联系人 + + + + +
+
+

添加联系人

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

+
+ +
+ + + + + + + \ No newline at end of file diff --git a/application.yml b/application.yml new file mode 100644 index 0000000..a71e60e --- /dev/null +++ b/application.yml @@ -0,0 +1,16 @@ +server: + port: 8080 + servlet: + context-path: /home + +spring: + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://127.0.0.1:3306/student?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai + password: 123456 + username: root + + +mybatis: + mapper-locations: classpath:MyBatis/*.xml + type-aliases-package: com.example.webproject.com.Pojo diff --git a/control.java b/control.java new file mode 100644 index 0000000..cd260c3 --- /dev/null +++ b/control.java @@ -0,0 +1,256 @@ +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; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +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 +public class control { + @Autowired + public account_operator account_operator; + @Autowired + public user_data_operator user_data_operator; + + + + //这个是访问登录界面 + @GetMapping("/index") + public String test()throws Exception{ + System.out.println("index"); + // 注意在使用thymleaf时要注意 版本要和starter-web的要配合使用 + //否者会跳转不到相应的界面 + return "Login"; + } + + + //这里要开始编写我们的对于账号上面的处理了 + @RequestMapping("/postProcessorRegistration") + + public ModelAndView postProcessorRegistration(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse,@RequestParam Map map){ + System.out.println("postProcessorRegistration"); + //这里我们是进行注册操作 + //我们先去数据库里面查一下,有没有这个账号 + //有就给出错误 + //否则就将其插入 + //不能获取model 要获取modelMap +// Map model = modelAndView.getModel(); + + String account = (String)map.get("account"); + String password = (String)map.get("password"); + ModelAndView modelAndView = new ModelAndView(); + account one = account_operator.findOne(account); + System.out.println("数据库中查询的值: "+one); + if(one == null){ + System.out.println("数据库中不存在,进行插入操作"); + account_operator.insertOne(new account(account,password)); + System.out.println("插入完成"); + //在这里我们要将账号创建成功的消息显示出来 + modelAndView.setViewName("Login"); + modelAndView.addObject("isHaveAccount",""); + }else{ + //在这里我们要将账号已近存在的消息回显 + modelAndView.setViewName("Login"); + modelAndView.addObject("isHaveAccount","当前账号已有"); + } + + + return modelAndView; + } + + //这里要开始编写我们的对于账号上面的处理了 + @RequestMapping("/postProcessorLogin") +// @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("还没有账号,请注册一个"); + //将没有账号显示出去,提醒用户注册账号 + modelAndView.addObject("isHaveAccount","还没有账号,注册一个"); + modelAndView.setViewName("Login"); + }else{ + if((one.getTxl_password().equals(password))){ + System.out.println("密码正确,登入成功"); +// 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"); + } + } + 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 + Integer col = user_data_operator.deleteOne(account,name); + if(col != 0){ + modelAndView.addObject("message","删除成功"); + }else{ + 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/data_operator.html b/data_operator.html new file mode 100644 index 0000000..42d71da --- /dev/null +++ b/data_operator.html @@ -0,0 +1,206 @@ + + + + + + Title + + + + + + + + + + + + +
+ +
+ + + +
+ + + + + +
+ + + + + + + + + + + + + + + + + +
+
+
+ + + \ No newline at end of file diff --git a/delete_user_data.html b/delete_user_data.html new file mode 100644 index 0000000..dc957bd --- /dev/null +++ b/delete_user_data.html @@ -0,0 +1,120 @@ + + + + + + + + 查找联系人 + + + + +
+
+

删除联系人

+
+
+ + +
+

+ +
+ + + + + \ No newline at end of file diff --git a/error.html b/error.html new file mode 100644 index 0000000..26beba6 --- /dev/null +++ b/error.html @@ -0,0 +1,10 @@ + + + + + Title + + + This is error page + + \ No newline at end of file diff --git a/find_user_data.html b/find_user_data.html new file mode 100644 index 0000000..bc8e7e6 --- /dev/null +++ b/find_user_data.html @@ -0,0 +1,120 @@ + + + + + + + + 查找联系人 + + + + +
+
+

查找联系人

+
+
+ + +
+

+ +
+ + + + + \ No newline at end of file diff --git a/user_data.java b/user_data.java new file mode 100644 index 0000000..238c06a --- /dev/null +++ b/user_data.java @@ -0,0 +1,40 @@ +package com.example.webproject.com.Pojo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class user_data { + private String txl_account; + private String txl_name; + private String txl_contact_phone_number; + private String txl_email; + private String txl_address; + private String txl_social_media_account; + private String txl_company_name; + private String txl_position; + private String txl_remarks; + private String txl_birthday; + private String txl_hobbies; + + @Override + public String toString() { + return "user_data{" + + "txl_account='" + txl_account + '\'' + + ", txl_name='" + txl_name + '\'' + + ", txl_contact_phone_number='" + txl_contact_phone_number + '\'' + + ", txl_email='" + txl_email + '\'' + + ", txl_address='" + txl_address + '\'' + + ", txl_social_media_account='" + txl_social_media_account + '\'' + + ", txl_company_name='" + txl_company_name + '\'' + + ", txl_position='" + txl_position + '\'' + + ", txl_remarks='" + txl_remarks + '\'' + + ", txl_birthday='" + txl_birthday + '\'' + + ", txl_hobbies='" + txl_hobbies + '\'' + + '}'; + } + +} diff --git a/user_data_operator.java b/user_data_operator.java new file mode 100644 index 0000000..ef73cc5 --- /dev/null +++ b/user_data_operator.java @@ -0,0 +1,22 @@ +package com.example.webproject.com.Mapper; + +import com.example.webproject.com.Pojo.user_data; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Select; + +import java.util.List; + +@Mapper +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/user_data_operator.xml b/user_data_operator.xml new file mode 100644 index 0000000..ea9942d --- /dev/null +++ b/user_data_operator.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + 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