此文章详细介绍了idea 搭建springboot步骤,以及简易的前后端通过ajax进行简单数据交互代码,二话不说,进入正题。
第一步、idea开发工具搭建springboot框架
来看下整个项目结构
第二步、pom依赖(自动生成的的不管就好)
4.0.0 org.springframework.boot spring-boot-starter-parent2.5.6 com.example demo0.0.1-SNAPSHOT demo Demo project for Spring Boot 1.8 org.springframework.boot spring-boot-starter-jdbcorg.springframework.boot spring-boot-starter-thymeleaforg.springframework.boot spring-boot-starter-weborg.mybatis.spring.boot mybatis-spring-boot-starter2.2.0 mysql mysql-connector-javaruntime org.springframework.boot spring-boot-starter-testtest 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:
程序代写、设计代做(毕设)、软件定制,价格优惠,有需要就点击程序客栈,或者联系博主



