亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

SpringBoot + vue2.0查詢所用功能詳解

 更新時(shí)間:2023年11月21日 09:47:29   作者:YE-  
這篇文章主要介紹了SpringBoot + vue2.0查詢所用功能,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧

導(dǎo)入數(shù)據(jù)庫(kù)文件

CREATE DATABASE `springboot` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci */ /*!80016 DEFAULT ENCRYPTION='N' */
CREATE TABLE `users` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(40) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL,
  `password` varchar(40) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL,
  `email` varchar(60) DEFAULT NULL,
  `birthday` date DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb3

后端

創(chuàng)建SpringBoot項(xiàng)目

第一步,導(dǎo)入pom.xml依賴

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-j</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <image>
                        <builder>paketobuildpacks/builder-jammy-base:latest</builder>
                    </image>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

第二步,編譯application.yml文件,連接數(shù)據(jù)庫(kù)

spring:
  datasource:
    url : jdbc:mysql://localhost:3306/springboot?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
    username : root
    password : 123456
    driver-class-name : com.mysql.cj.jdbc.Driver
  jpa: #自動(dòng)生成函數(shù)所帶的說(shuō)起來(lái)語(yǔ)句
    show-sql: true
    properties: 
      hibernate:
        format_sql: true
server:
  port: 8181

ps.確定端口號(hào)為8181,不能是8080,這樣會(huì)與前端沖突

第三步,撰寫(xiě)JavaBean

Users.java

package com.example.springboottest.entity;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import lombok.Data;
@Entity
@Data
public class Users {
    @Id
    private Integer id;
    private String name;
    private String password;
    private String email;
    private String birthday;
}

第四步,寫(xiě)一下儲(chǔ)存庫(kù)UsersRepository接口

UsersRepository.java

package com.example.springboottest.repository;
import com.example.springboottest.entity.Users;
import org.springframework.data.jpa.repository.JpaRepository;
public interface UsersRepository extends JpaRepository<Users, Integer> {
}

第五步,寫(xiě)一下連接層,與網(wǎng)絡(luò)連接

UserHandler.java

package com.example.springboottest.controller;
import com.example.springboottest.entity.Users;
import com.example.springboottest.repository.UsersRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping("/user")
public class UserHandler {
    @Autowired
    private UsersRepository usersRepository;
    @GetMapping("/findAll")
    public List<Users> findAll() {
        return usersRepository.findAll();
    }
}

第六步,CrosConfig.java

由于前后端端口不一,需要端口配置文件,將后端的URL可以傳給前端使用,需要這個(gè)文件

package com.example.springboottest.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class CrosConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
               .allowedOrigins("*")
               .allowedMethods("GET", "POST", "PUT", "DELETE")
               .allowedHeaders("*")
               .allowCredentials(false)
               .maxAge(3600);
    }
}

第七步,運(yùn)行

運(yùn)行SpringBootTestApplication.java文件,則localhost:8181端口啟動(dòng)

前端

創(chuàng)建一個(gè)有vuex,router路由的vue2.0前端項(xiàng)目

第一步,終端導(dǎo)入axios

輸入:vue add axios
ps.這個(gè)命令,我只在idea輸入成功,vscode不知道為什么輸入無(wú)效

src的文件出現(xiàn)了plugins文件夾就是成功標(biāo)志

第二步,在views界面創(chuàng)建User.vue前端vue界面

<template>
  <div>
    <table>
      <tr>
          <td>ID</td>
          <td>name</td>
          <td>password</td>
          <td>email</td>
          <td>birthday</td>
      </tr>
      <tr v-for="item in User">
        <td>{{ item.id }}</td>
        <td>{{item.name}}</td>
        <td>{{item.password}}</td>
        <td>{{item.email}}</td>
        <td>{{item.birthday}}</td>
      </tr>
    </table>
  </div>
</template>
<script>
export default {
      name: "User",
      data() {
        return {
            msg: "Hello User",
          User: [
            {
              id: 1,
              name: "name",
              password: "password",
              email: "email",
              birthday: "birthday"
            }]
        }
    },
    created() {
          const _this=this;
          axios.get('http://localhost:8181/user/findAll').then(function (resp){
              _this.User = resp.data;
          })
        }
} <!--寫(xiě)上ajax代碼,用于查詢所有數(shù)據(jù)-->
</script>
<style>
</style>

第三步,導(dǎo)入剛剛寫(xiě)的文件路由

在router路由文件導(dǎo)入U(xiǎn)ser.vue路由

import User from '../views/User.vue'
  {
    path: '/user',
    component: User
  }

這樣就能在前端查看User.vue了

第四步,前端終端輸入npm run serve 啟動(dòng)項(xiàng)目,localhost:8080啟動(dòng)結(jié)果測(cè)試

測(cè)試成功

到此這篇關(guān)于SpringBoot + vue2.0查詢所用功能的文章就介紹到這了,更多相關(guān)springboot查詢功能內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Java DWR內(nèi)存泄漏問(wèn)題解決方案

    Java DWR內(nèi)存泄漏問(wèn)題解決方案

    這篇文章主要介紹了Java DWR內(nèi)存泄漏問(wèn)題解決方案,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-10-10
  • Spring Boot整合FTPClient線程池的實(shí)現(xiàn)示例

    Spring Boot整合FTPClient線程池的實(shí)現(xiàn)示例

    這篇文章主要介紹了Spring Boot整合FTPClient線程池的實(shí)現(xiàn)示例,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-12-12
  • mybatis-plus更新策略部分字段不更新問(wèn)題

    mybatis-plus更新策略部分字段不更新問(wèn)題

    這篇文章主要介紹了mybatis-plus更新策略部分字段不更新問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-03-03
  • MyBatis+MyBatisPlus中遇到的一些坑及解決

    MyBatis+MyBatisPlus中遇到的一些坑及解決

    這篇文章主要介紹了MyBatis+MyBatisPlus中遇到的一些坑及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-03-03
  • Java的volatile和sychronized底層實(shí)現(xiàn)原理解析

    Java的volatile和sychronized底層實(shí)現(xiàn)原理解析

    文章詳細(xì)介紹了Java中的synchronized和volatile關(guān)鍵字的底層實(shí)現(xiàn)原理,包括字節(jié)碼層面、JVM層面的實(shí)現(xiàn)細(xì)節(jié),以及鎖的類型和MESI協(xié)議在多核處理器中的作用,文章還探討了synchronized和volatile的區(qū)別,以及如何通過(guò)Atomic類來(lái)實(shí)現(xiàn)更細(xì)粒度的原子操作,感興趣的朋友一起看看吧
    2025-03-03
  • JavaWeb中web.xml初始化加載順序詳解

    JavaWeb中web.xml初始化加載順序詳解

    本篇文章主要介紹了JavaWeb中web.xml初始化加載順序詳解,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-05-05
  • Jedis對(duì)redis的五大類型操作代碼詳解

    Jedis對(duì)redis的五大類型操作代碼詳解

    這篇文章主要介紹了Jedis對(duì)redis的五大操作代碼詳解,分別是字符串、列表、散列、集合、有序集合,具有一定參考價(jià)值,需要的朋友可以了解下。
    2017-11-11
  • Java并發(fā)系列之ConcurrentHashMap源碼分析

    Java并發(fā)系列之ConcurrentHashMap源碼分析

    這篇文章主要為大家詳細(xì)分析了Java并發(fā)系列之ConcurrentHashMap源碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-03-03
  • Java編程實(shí)現(xiàn)直接插入排序代碼示例

    Java編程實(shí)現(xiàn)直接插入排序代碼示例

    這篇文章主要介紹了Java編程實(shí)現(xiàn)直接插入排序代碼示例,具有一定借鑒價(jià)值,需要的朋友可以參考下。
    2017-12-12
  • 詳解Spring中接口的bean是如何注入的

    詳解Spring中接口的bean是如何注入的

    這篇文章主要介紹了詳解Spring中接口的bean是如何注入的的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Spring具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-06-06

最新評(píng)論