栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

【Demo】idea搭建SpringBoot和AJAX前后端数据交互

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【Demo】idea搭建SpringBoot和AJAX前后端数据交互

此文章详细介绍了idea 搭建springboot步骤,以及简易的前后端通过ajax进行简单数据交互代码,二话不说,进入正题。
第一步、idea开发工具搭建springboot框架




来看下整个项目结构

第二步、pom依赖(自动生成的的不管就好)



    4.0.0
    
        org.springframework.boot
        spring-boot-starter-parent
        2.5.6
         
    
    com.example
    demo
    0.0.1-SNAPSHOT
    demo
    Demo project for Spring Boot
    
        1.8
    
    
        
            org.springframework.boot
            spring-boot-starter-jdbc
        
        
            org.springframework.boot
            spring-boot-starter-thymeleaf
        
        
            org.springframework.boot
            spring-boot-starter-web
        
        
            org.mybatis.spring.boot
            mybatis-spring-boot-starter
            2.2.0
        

        
            mysql
            mysql-connector-java
            runtime
        
        
            org.springframework.boot
            spring-boot-starter-test
            test
        
    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    


第三步、新建controller包

package com.example.demo.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("demo")
public class indexController {

    @RequestMapping("")
    public String show(){
        return "index";
    }

    @RequestMapping("/index")
    public String index(@RequestParam("text") String text){
        System.out.printf("接收前端值:"+text);
        return "index";
    }

}

第四步、静态目录下添加并编写前端代码

1、配置文件添加代码

    thymeleaf.prefix: classpath:/templates/
    thymeleaf.suffix: .html
    thymeleaf.mode: HTML
    thymeleaf.encoding: UTF-8
    thymeleaf.servlet.content-type: text/html
    thymeleaf.cache: false
    resources.static-locations: classpath:/static/
    mvc.static-path-pattern: /static/**

2、编写index.html




    
    test
    








运行

友情Tip:
程序代写、设计代做(毕设)、软件定制,价格优惠,有需要就点击程序客栈,或者联系博主

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/490624.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号