久久综合九色综合97婷婷-美女视频黄频a免费-精品日本一区二区三区在线观看-日韩中文无码有码免费视频-亚洲中文字幕无码专区-扒开双腿疯狂进出爽爽爽动态照片-国产乱理伦片在线观看夜-高清极品美女毛茸茸-欧美寡妇性猛交XXX-国产亚洲精品99在线播放-日韩美女毛片又爽又大毛片,99久久久无码国产精品9,国产成a人片在线观看视频下载,欧美疯狂xxxx吞精视频

有趣生活

當前位置:首頁>知識>正確的郵箱qq格式怎么寫(個人電子郵箱填寫方法)

正確的郵箱qq格式怎么寫(個人電子郵箱填寫方法)

發(fā)布時間:2024-01-24閱讀(20)

導讀1、登錄注冊思路這是一個使用springboot做的一個qq郵箱注冊和登錄的項目。沒寫前端頁面,使用postman測試。有截圖詳細。1.1、思路注冊:通過輸....

1、登錄注冊思路

這是一個使用spring boot做的一個qq郵箱注冊和登錄的項目。沒寫前端頁面,使用postman測試。有截圖詳細。

1.1、思路

注冊:通過輸入的郵箱發(fā)送驗證碼,檢驗前端傳來的驗證碼是否和后臺生成的一致,若一致,將數(shù)據(jù)寫入數(shù)據(jù)庫,完成注冊;

登錄:通過輸入的郵箱查詢密碼,然后比較密碼是否一致,一致就是登錄成功。

1.2、整個項目結構圖

正確的郵箱qq格式怎么寫(個人電子郵箱填寫方法)(1)

2、準備

2.1、開啟郵箱POP3/SMTP服務

登錄qq郵箱后,點擊左上方的設置,選擇賬戶,如下圖。

正確的郵箱qq格式怎么寫(個人電子郵箱填寫方法)(2)

然后一直往下滑,看到如下圖的POP3/SMTP服務,點擊開啟,應該會讓幫定的手機號發(fā)個短信,然后會收到一個授權碼,一定要好好保存,在appliction.properties配置中會用到。

正確的郵箱qq格式怎么寫(個人電子郵箱填寫方法)(3)

2.2、創(chuàng)建一個spring boot項目的時候,一直確認,jdk選擇8。

下邊是pom.xml中<dependencies>標簽的全部依賴

         <dependencies>       <dependency>           <groupId>org.springframework.boot</groupId>           <artifactId>spring-boot-starter</artifactId>       </dependency>       <dependency>           <groupId>org.springframework.boot</groupId>           <artifactId>spring-boot-starter-test</artifactId>           <scope>test</scope>       </dependency>       <!--web-->       <dependency>           <groupId>org.springframework.boot</groupId>           <artifactId>spring-boot-starter-web</artifactId>       </dependency>       <dependency>           <groupId>org.springframework.boot</groupId>           <artifactId>spring-boot-starter-mail</artifactId>       </dependency>       <!--mybatis-->       <dependency>           <groupId>org.mybatis.spring.boot</groupId>           <artifactId>mybatis-spring-boot-starter</artifactId>           <version>1.3.2</version>       </dependency>       <!--jdbc-->       <dependency>           <groupId>mysql</groupId>           <artifactId>mysql-connector-java</artifactId>           <version>8.0.19</version>       </dependency>       <dependency>           <groupId>org.springframework.boot</groupId>           <artifactId>spring-boot-starter-jdbc</artifactId>       </dependency>????</dependencies>

2.3、application.properties配置文件

application.properties配置文件

#郵箱配置#平臺地址,這里用的是qq郵箱,使用其他郵箱請更換spring.mail.host = smtp.qq.com#改成自己的郵箱spring.mail.username = xxxxx@qq.com#發(fā)送短信后它給你的授權碼 填寫到這里spring.mail.password = xxxxxx#這東西不用改spring.mail.properties.mail.smtp.ssl.enable=true##編碼格式spring.mail.default-encoding=UTF-8#數(shù)據(jù)庫相關配置spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driverspring.datasource.url=jdbc:mysql://localhost:3306/email?useSSL=true&characterEncoding=utf-8&serverTimezone=UTCspring.datasource.username=rootspring.datasource.password=root        #配置mappermybatis.mapper-locations=classpath:mapper/*.xml

2.4、創(chuàng)建數(shù)據(jù)庫

數(shù)據(jù)庫結構如下圖

正確的郵箱qq格式怎么寫(個人電子郵箱填寫方法)(4)

創(chuàng)建一個數(shù)據(jù)庫email

CREATE?DATABASE?email;

在email數(shù)據(jù)庫創(chuàng)建user表

CREATE TABLE `user` (  `id` int(20) NOT NULL AUTO_INCREMENT,  `username` varchar(255) NOT NULL,  `password` varchar(255) NOT NULL,  `email` varchar(255) NOT NULL,  PRIMARY KEY (`id`))?ENGINE=InnoDB?AUTO_INCREMENT=6?DEFAULT?CHARSET=utf8;

3、全部代碼類

如最上邊的項目結構圖。controller包是和前端對接的,mapper包中是接口,pojo是實體類,service層是邏輯代碼,vo包是前端發(fā)送數(shù)據(jù)暫時保存。

執(zhí)行流程: 使用postman發(fā)送請求,controller中會接受,然后調(diào)用service中的邏輯代碼,service會調(diào)用的mapper中接口,mapper的對應的xml實現(xiàn)對數(shù)據(jù)庫的各種操作。

3.1、UserController.java

package com.lu.youxiang.controller;import com.lu.youxiang.service.MailService;import com.lu.youxiang.vo.UserVo;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.PostMapping;import org.springframework.web.bind.annotation.ResponseBody;import javax.servlet.http.HttpSession;@Controllerpublic class UserController {    @Autowired    private MailService mailService;    @PostMapping("/sendEmail")    @ResponseBody    public String sendEmail(String email, HttpSession httpSession){        mailService.sendMimeMail(email, httpSession);        return "sucess";    }    @PostMapping("/regist")    @ResponseBody    public String regist(UserVo userVo, HttpSession session){        mailService.registered(userVo,session);        return "sucess";    }    @PostMapping("/login")    @ResponseBody    public String login(String email, String password){        mailService.loginIn(email,password);        return "sucess";    }}

3.2、UserMapper.java

package com.lu.youxiang.mapper;import com.lu.youxiang.pojo.User;import org.apache.ibatis.annotations.Mapper;import org.springframework.stereotype.Repository;@Mapper@Repositorypublic interface UserMapper {    /**     * 注冊,插入數(shù)據(jù)     * @param user     */    void insertUser(User user);    /**     * 根據(jù)郵箱查詢     * @param email     * @return     */    User queryByEmail(String email);}

3.3、User.java

package com.lu.youxiang.pojo;public class User {    private String username;    private String password;    private String email;      //get和set方法省略了,自己生成一下}

3.4、MailService.java ,重要。

package com.lu.youxiang.service;import com.lu.youxiang.mapper.UserMapper;import com.lu.youxiang.pojo.User;import com.lu.youxiang.vo.UserVo;import com.lu.youxiang.vo.UserVoToUser;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.beans.factory.annotation.Value;import org.springframework.mail.SimpleMailMessage;import org.springframework.mail.javamail.JavaMailSender;import org.springframework.stereotype.Service;import javax.servlet.http.HttpSession;import java.util.Random;@Servicepublic class MailService {    @Autowired    private JavaMailSender mailSender;//一定要用@Autowired    @Autowired    private UserMapper userMapper;//注入UserMapper,交給bena    //application.properties中已配置的值    @Value("${spring.mail.username}")    private String from;    /**     * 給前端輸入的郵箱,發(fā)送驗證碼     * @param email     * @param session     * @return     */    public boolean sendMimeMail( String email, HttpSession session) {        try {            SimpleMailMessage mailMessage = new SimpleMailMessage();            mailMessage.setSubject("驗證碼郵件");//主題            //生成隨機數(shù)            String code = randomCode();            //將隨機數(shù)放置到session中            session.setAttribute("email",email);            session.setAttribute("code",code);            mailMessage.setText("您收到的驗證碼是:"+code);//內(nèi)容            mailMessage.setTo(email);//發(fā)給誰            mailMessage.setFrom(from);//你自己的郵箱            mailSender.send(mailMessage);//發(fā)送            return  true;        }catch (Exception e){            e.printStackTrace();            return false;        }    }    /**     * 隨機生成6位數(shù)的驗證碼     * @return String code     */    public String randomCode(){        StringBuilder str = new StringBuilder();        Random random = new Random();        for (int i = 0; i < 6; i++) {            str.append(random.nextInt(10));        }        return str.toString();    }    /**     * 檢驗驗證碼是否一致     * @param userVo     * @param session     * @return     */    public boolean registered(UserVo userVo, HttpSession session){        //獲取session中的驗證信息        String email = (String) session.getAttribute("email");        String code = (String) session.getAttribute("code");        //獲取表單中的提交的驗證信息        String voCode = userVo.getCode();        //如果email數(shù)據(jù)為空,或者不一致,注冊失敗        if (email == null || email.isEmpty()){            //return "error,請重新注冊";            return false;        }else if (!code.equals(voCode)){            //return "error,請重新注冊";            return false;        }        //保存數(shù)據(jù)        User user = UserVoToUser.toUser(userVo);        //將數(shù)據(jù)寫入數(shù)據(jù)庫        userMapper.insertUser(user);        //跳轉成功頁面        return true;    }    /**     * 通過輸入email查詢password,然后比較兩個password,如果一樣,登錄成功     * @param email     * @param password     * @return     */    public boolean loginIn(String email, String password){        User user = userMapper.queryByEmail(email);        if(!user.getPassword().equals(password)){            return false;        }        System.out.println("登錄成功:數(shù)據(jù)庫密碼是:"+user.getPassword());        return true;    }}

3.5、UserVo.java

package com.lu.youxiang.vo;public class UserVo {    private String username;    private String password;    private String email;    //    驗證碼    private String code;    //省略了get和set方法,自己生成一下?}

3.6、UserVoToUser.java

package com.lu.youxiang.vo;import com.lu.youxiang.pojo.User;public class UserVoToUser {    /**     * 將表單中的對象轉化為數(shù)據(jù)庫中存儲的用戶對象(剔除表單中的code)     * @param userVo     * @return     */    public static User toUser(UserVo userVo) {        //創(chuàng)建一個數(shù)據(jù)庫中存儲的對象        User user = new User();        //傳值        user.setUsername(userVo.getUsername());        user.setPassword(userVo.getPassword());        user.setEmail(userVo.getEmail());        // 返回包裝后的對象        return user;    }}

主配置類不復制了,創(chuàng)建springboot項目后,就有。

3.7、UserMapper.xml在resources包下創(chuàng)建mapper包,用來放xml,然后再這個包中創(chuàng)建UserMapper.xml,內(nèi)容如下。

<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE mapper        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"        "http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mapper namespace="com.lu.youxiang.mapper.UserMapper">    <insert id="insertUser" parameterType="com.lu.youxiang.pojo.User">        insert into user (username,password,email)         values (#{username},#{password},#{email})    </insert>    <select id="queryByEmail" resultType="com.lu.youxiang.pojo.User">        select *        from user        where email = #{email}    </select></mapper>

4、使用postman測試

如果沒有這個軟件,安裝一下,使用很簡單。打開后,點擊左上角的file,再點擊New Tab,就會出來一個頁面。(或者使用Ctrl+T快捷鍵)

4.1、測試發(fā)送郵件

請求url:

http://localhost:8080/sendEmail?email=123456@qq.com

把請求url復制到如下如的url中, 郵箱換成自己的,請求方式換成POST。點擊send。如下圖

正確的郵箱qq格式怎么寫(個人電子郵箱填寫方法)(5)

4.2、測試注冊

請求url:

http://localhost:8080/regist

把請求url復制到如下如的url中, 郵箱換成自己的,code的值寫郵箱收到的,請求方式換成POST。點擊send,如下圖

正確的郵箱qq格式怎么寫(個人電子郵箱填寫方法)(6)

4.3、測試登錄

請求url:

http://localhost:8080/login?email=123456@qq.com&password=12345

復制url,改成POST請求,點擊Send。

如下圖:

正確的郵箱qq格式怎么寫(個人電子郵箱填寫方法)(7)

歡迎分享轉載→http://www.avcorse.com/read-210084.html

Copyright ? 2024 有趣生活 All Rights Reserve吉ICP備19000289號-5 TXT地圖HTML地圖XML地圖