最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

SpringBoot結(jié)合Ajax實(shí)現(xiàn)登錄頁(yè)面實(shí)例

 更新時(shí)間:2022年02月10日 11:21:38   作者:路上的追夢(mèng)人  
大家好,本篇文章主要講的是SpringBoot結(jié)合Ajax實(shí)現(xiàn)登錄頁(yè)面實(shí)例,感興趣的同學(xué)趕快來看一看,對(duì)你有幫助的話記得收藏一下

一、 Ajax

1.1 Ajax介紹

AJAX 是一種在無需重新加載整個(gè)網(wǎng)頁(yè)的情況下,能夠更新部分網(wǎng)頁(yè)的技術(shù)。

AJAX = 異步 JavaScript 和 XML

AJAX 是一種用于創(chuàng)建快速動(dòng)態(tài)網(wǎng)頁(yè)的技術(shù)。通過在后臺(tái)與服務(wù)器進(jìn)行少量數(shù)據(jù)交換,可以使網(wǎng)頁(yè)實(shí)現(xiàn)異步更新。這意味著可以在不重新加載整個(gè)網(wǎng)頁(yè)的情況下,對(duì)網(wǎng)頁(yè)的某部分進(jìn)行更新。傳統(tǒng)的網(wǎng)頁(yè)(不使用 AJAX)如果需要更新內(nèi)容,必需重載整個(gè)網(wǎng)頁(yè)面。

AJAX即Asynchronous JavaScript and XML(異步JavaScript和XML),是實(shí)現(xiàn)客戶端和服務(wù)器異步通信的方法;同步:請(qǐng)求和頁(yè)面的跳轉(zhuǎn)同時(shí)發(fā)生;異步:請(qǐng)求和頁(yè)面的跳轉(zhuǎn)不同時(shí)發(fā)生;異步的請(qǐng)求可以實(shí)現(xiàn)頁(yè)面的局部刷新;

 1.2 異步的作用

節(jié)省流量;無需刷新整個(gè)頁(yè)面,服務(wù)器壓力也降低;用戶體驗(yàn)好;

 二、SpringBoot應(yīng)用Ajax

2.1 開發(fā)配置

IDEA項(xiàng)目目錄

pom.xml配置 

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.1.4</version>
        </dependency>
 
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.2.8</version>
        </dependency>
 
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
    </dependencies>

application.yml

# 應(yīng)用名稱
spring:
  application:
    name: springboot-ajax
  # thymeleaf模板
  thymeleaf:
    cache: true
    check-template: true
    check-template-location: true
    enabled: true
    encoding: UTF-8
    mode: HTML5
    prefix: classpath:/templates/
    suffix: .html
 
# 數(shù)據(jù)源
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/ajax?serverTimezone=UTC
    username: root
    password: 1234
    type: com.alibaba.druid.pool.DruidDataSource
 
# 應(yīng)用服務(wù) WEB 訪問端口
server:
  port: 8080
 
mybatis:
  configuration:
    map-underscore-to-camel-case: true
 
 

 2.2 創(chuàng)建user表 

SQL實(shí)現(xiàn)

drop table if exists user;
create table user(
id int(8) NOT NULL AUTO_INCREMENT,
loginName varchar(30) NULL DEFAULT NULL,
loginPwd varchar(20) NULL DEFAULT NULL,
realName varchar(30) NULL DEFAULT NULL,
PRIMARY KEY(id) USING BTREE
)ENGINE=INNODB AUTO_INCREMENT=3 ROW_FORMAT=Dynamic;
 
insert into user values(1,'XiaoChen,'123456','小陳');
insert into user values(2,'XiaoWang','123456','小王');
insert into user values(3,'XiaoHua','123456','小花');

2.3 MVC三層架構(gòu)

1)Entity實(shí)體類

user對(duì)象

@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class User {
    private int id;
    private String loginName;
    private String loginPwd;
    private String realName;
}

mapper接口

@Mapper
@Repository
public interface UserMapper {
    @Select("select * from user")
    public List<User> queryUsers();
}

2) Service業(yè)務(wù)層

service層

public interface UserService {
    public List<User> queryAllUsers();
}

serviceImpl層

@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;
 
    @Override
    public List<User> queryAllUsers() {
        return userMapper.queryUsers();
    }
}

3)Controller層

@RestController
@CrossOrigin //解決跨域問題
public class UserController {
    @Resource
    private UserServiceImpl userServiceImpl;
 
    @RequestMapping("/xiaoChen")
    public String index(String name,String pwd){
        String msg="";
        List<User> users=userServiceImpl.queryAllUsers();
        User myUser=null;
        for(User user:users){
            if(user.getLoginName().equals(name)){
                myUser=user;
                msg="OK";
                break;
            }else{
                msg="賬號(hào)錯(cuò)誤";
            }
        }
        if(pwd!=null){
            if(myUser!=null&&myUser.getLoginPwd().equals(pwd)){
                msg="OK";
            }else{
                msg="密碼錯(cuò)誤";
            }
        }
        return msg;
    }
}

2.4 前端測(cè)試頁(yè)面

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Ajax登錄頁(yè)面</title>
    <script src="/js/jquery-3.6.0.min.js"></script>
</head>
<body>
    <p>
        賬號(hào):<input type="text" id="name" onblur="test1()"/>
        <span id="username"></span>
    </p>
    <p>
        密碼:<input type="text" id="pwd" onblur="test2()"/>
        <span id="userpwd"></span>
    </p>
    <script type="text/javascript">
        function test1(){
            $.post({
                url:"http://localhost:8080/xiaoChen",
                data:{'name':$("#name").val()},
                success:function(data){
                    if(data.toString()=='OK'){
                        $("#username").css("color","green");
                    }else{
                        $("#username").css("color","red");
                    }
                    $("#username").html(data);
                }
            });
        }
        function test2(){
            $.post({
                url: "http://localhost:8080/xiaoChen",
                data: {'pwd': $("#pwd").val()},
                success: function (data) {
                    if (data.toString()=='OK') {
                        $("#userpwd").css("color", "green");
                    } else {
                        $("#userpwd").css("color", "red");
                    }
                    $("#userpwd").html(data);
                }
            });
        }
    </script>
</body>
</html>

2.5 測(cè)試結(jié)果

總結(jié)

到此這篇關(guān)于SpringBoot結(jié)合Ajax實(shí)現(xiàn)登錄頁(yè)面實(shí)例的文章就介紹到這了,更多相關(guān)SpringBoot登錄頁(yè)面內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Spring boot整合shiro+jwt實(shí)現(xiàn)前后端分離

    Spring boot整合shiro+jwt實(shí)現(xiàn)前后端分離

    這篇文章主要為大家詳細(xì)介紹了Spring boot整合shiro+jwt實(shí)現(xiàn)前后端分離,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-12-12
  • hadoop運(yùn)行java程序(jar包)并運(yùn)行時(shí)動(dòng)態(tài)指定參數(shù)

    hadoop運(yùn)行java程序(jar包)并運(yùn)行時(shí)動(dòng)態(tài)指定參數(shù)

    這篇文章主要介紹了hadoop如何運(yùn)行java程序(jar包)并運(yùn)行時(shí)動(dòng)態(tài)指定參數(shù),使用hadoop 運(yùn)行 java jar包,Main函數(shù)一定要加上全限定類名,需要的朋友可以參考下
    2021-06-06
  • Springboot如何集成jodconverter做文檔轉(zhuǎn)換

    Springboot如何集成jodconverter做文檔轉(zhuǎn)換

    這篇文章主要介紹了Springboot如何集成jodconverter做文檔轉(zhuǎn)換問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-08-08
  • 基于JDBC封裝的BaseDao(實(shí)例代碼)

    基于JDBC封裝的BaseDao(實(shí)例代碼)

    下面小編就為大家?guī)硪黄贘DBC封裝的BaseDao(實(shí)例代碼)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2016-07-07
  • Mybatis傳list參數(shù)調(diào)用oracle存儲(chǔ)過程的解決方法

    Mybatis傳list參數(shù)調(diào)用oracle存儲(chǔ)過程的解決方法

    怎么利用MyBatis傳List類型參數(shù)到數(shù)據(jù)庫(kù)存儲(chǔ)過程中實(shí)現(xiàn)批量插入數(shù)據(jù)?接下來通過本文給大家介紹Mybatis傳list參數(shù)調(diào)用oracle存儲(chǔ)過程,需要的朋友可以參考下
    2017-03-03
  • Java 重寫時(shí)應(yīng)當(dāng)遵守的 11 條規(guī)則

    Java 重寫時(shí)應(yīng)當(dāng)遵守的 11 條規(guī)則

    這篇文章主要介紹了Java 重寫時(shí)應(yīng)當(dāng)遵守的 11 條規(guī)則,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-03-03
  • Spring boot熱部署devtools過程解析

    Spring boot熱部署devtools過程解析

    這篇文章主要介紹了Spring boot熱部署devtools過程解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-07-07
  • SpringBoot結(jié)合Redis實(shí)現(xiàn)接口冪等性的示例代碼

    SpringBoot結(jié)合Redis實(shí)現(xiàn)接口冪等性的示例代碼

    本文主要介紹了SpringBoot結(jié)合Redis實(shí)現(xiàn)接口冪等性的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-06-06
  • java實(shí)現(xiàn)俄羅斯方塊游戲

    java實(shí)現(xiàn)俄羅斯方塊游戲

    這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)俄羅斯方塊游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-02-02
  • java仿windows記事本功能完整版

    java仿windows記事本功能完整版

    這篇文章主要為大家詳細(xì)介紹了java仿windows記事本功能完整版,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-03-03

最新評(píng)論

高陵县| 大渡口区| 桑日县| 若尔盖县| 石柱| 阿坝县| 文山县| 保靖县| 乐至县| 延津县| 绥中县| 伊川县| 邳州市| 格尔木市| 抚远县| 武乡县| 怀宁县| 光泽县| 鹿泉市| 延寿县| 双江| 五莲县| 重庆市| 黄浦区| 郁南县| 双桥区| 鹤峰县| 嘉黎县| 丹凤县| 青龙| 东平县| 红河县| 北川| 龙胜| 房山区| 赤壁市| 独山县| 大连市| 神农架林区| 抚顺县| 孙吴县|