国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

頁(yè)面數(shù)據(jù)類(lèi)型為json,后端接受json數(shù)據(jù)

這篇具有很好參考價(jià)值的文章主要介紹了頁(yè)面數(shù)據(jù)類(lèi)型為json,后端接受json數(shù)據(jù)。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

項(xiàng)目結(jié)構(gòu)

頁(yè)面數(shù)據(jù)類(lèi)型為json,后端接受json數(shù)據(jù),springmvc,java,json,json

依賴(lài)pom.xml

<dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>5.2.8.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>5.2.8.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
      <version>2.9.5</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>

web.xml

<?xml version="1.0" encoding="UTF-8" ?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
    id="WebApp_ID" version="3.1">

<!--  配置前端控制器-->
  <servlet>
    <servlet-name>dispatcherServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:spring.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>dispatcherServlet</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>

<!--  編碼過(guò)濾器-->
  <filter>
    <filter-name>encodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
      <param-name>encoding</param-name>
      <param-value>UTF-8</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>encodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
</web-app>


addStudent.jsp

取得input 的輸入值然后編寫(xiě)json數(shù)據(jù),JSON.stringify(student) 將student 轉(zhuǎn)化為json對(duì)象


<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="/JQ/jquery.js"></script>
    <script>
        $(function (){
            $(":button").click(function (){
                let student = {
                    "id":$("[name=id]:text").val(),
                    "name":$("[name=name]:text").val(),
                    "age":$("[name=age]:text").val(),
                    "subject":$("[name=subject]:text").val(),
                    "address":$("[name=address]:text").val()
                };
                $.ajax({
                    "url":"http://localhost:8080/testAjax",
                    "type":"POST",
                    "dataType":"json",
                    "contentType":"application/json",
                    "data":JSON.stringify(student),
                    "success":function (data){
                        console.log(data)
                    }
                })
            })
        })
    </script>
</head>
<body>
<div>
    <input type="text" name="id" placeholder="ID"><br>
    <input type="text" name="name" placeholder="name"><br>
    <input type="text" name="age" placeholder="age"><br>
    <input type="text" name="subject" placeholder="subject"><br>
    <input type="text" name="address" placeholder="address"><br>
    <input type="button" value="添加"><br>
</div>
</body>
</html>

Student實(shí)體類(lèi),get set toString方法

頁(yè)面數(shù)據(jù)類(lèi)型為json,后端接受json數(shù)據(jù),springmvc,java,json,json文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-803094.html

StudentController代碼

package com.tmg.controller;

import com.tmg.domain.Student;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
public class StudentController {

    List<Student> students=new ArrayList<>();
    @ResponseBody
    @RequestMapping("testAjax")
    public List<Student> testAjax(@RequestBody Student student){
        students.add(student);
        return students;
    }

    @RequestMapping("hello")
    public String toIndex(){
        System.out.println("hello");
        return "addStudent";
    }
}

resources下spring.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <context:component-scan base-package="com.tmg"></context:component-scan>

<!--    配置視圖解析器-->
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/pages/"></property>
        <property name="suffix" value=".jsp"></property>
    </bean>

<!--   配置靜態(tài)資源的處理器 -->
    <mvc:default-servlet-handler></mvc:default-servlet-handler>

<!--    配置注解驅(qū)動(dòng)-->
    <mvc:annotation-driven></mvc:annotation-driven>


</beans>

到了這里,關(guān)于頁(yè)面數(shù)據(jù)類(lèi)型為json,后端接受json數(shù)據(jù)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶(hù)投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 后端java 如何返回給前端 JSON數(shù)據(jù)

    在上述代碼中,@ResponseBody注解用于將Java List對(duì)象轉(zhuǎn)換為JSON格式的數(shù)據(jù),并返回給前端。Spring會(huì)自動(dòng)將List對(duì)象轉(zhuǎn)換為JSON格式的數(shù)組,其中每個(gè)元素都是一個(gè)JSON對(duì)象。在本例中,每個(gè)JSON對(duì)象都包含一個(gè)name屬性和一個(gè)age屬性。 Regenerate

    2024年02月15日
    瀏覽(21)
  • java后端該怎樣來(lái)接受前端日期選擇器傳入的時(shí)間參數(shù)

    如果前端使用了日期選擇器并且將選擇的日期傳給了Java后端,那么Java后端可以使用如下方法來(lái)接收日期參數(shù): 在后端的方法中聲明一個(gè)形參,類(lèi)型為 java.util.Date 或 java.time.LocalDate ,然后在前端的請(qǐng)求中傳入的日期參數(shù)會(huì)被自動(dòng)封裝成相應(yīng)的日期對(duì)象。例如: 在后端的方法

    2024年02月13日
    瀏覽(40)
  • 【SpringMVC篇】5種類(lèi)型參數(shù)傳遞&&json數(shù)據(jù)傳參

    【SpringMVC篇】5種類(lèi)型參數(shù)傳遞&&json數(shù)據(jù)傳參

    ??專(zhuān)欄【SpringMVC】 ??喜歡的詩(shī)句:天行健,君子以自強(qiáng)不息。 ??音樂(lè)分享【如愿】 ??歡迎并且感謝大家指出小吉的問(wèn)題?? 在Web項(xiàng)目開(kāi)發(fā)中,如何獲取客戶(hù)端傳來(lái)的參數(shù)是非常重要的功能。SpringMVC提供了全面靈活的請(qǐng)求參數(shù)綁定機(jī)制,大大簡(jiǎn)化了參數(shù)處理。 本文將全面介紹

    2024年02月06日
    瀏覽(30)
  • Spring 從Postman發(fā)送的數(shù)據(jù),后端接受變成null了?!

    Spring 從Postman發(fā)送的數(shù)據(jù),后端接受變成null了?!

    今天遇到了個(gè)奇怪的問(wèn)題,用Postman給后端發(fā)JSON格式的數(shù)據(jù),結(jié)果,發(fā)來(lái)全是null,在網(wǎng)上找了很多方法都不行??梢钥纯慈缦碌牟僮鳎?設(shè)計(jì)的domain類(lèi) 接受相關(guān)JSON的Mapping Postman發(fā)送的數(shù)據(jù) 就按上面這么做,點(diǎn)擊“Send”,結(jié)果如下: 經(jīng)過(guò)一番嘗試,我猜測(cè)應(yīng)該是沒(méi)有相應(yīng)的構(gòu)

    2024年02月11日
    瀏覽(25)
  • Java后端使用POST請(qǐng)求向mysql中插入Json數(shù)據(jù)的問(wèn)題

    Cause: java.lang.IllegalStateException: Type handler was null on parameter mapping for property ‘urlParams’. It was either not specified and/or could not be found for the javaType (com.alibaba.fastjson.JSONObject) : jdbcType (null) combination.

    2024年02月07日
    瀏覽(21)
  • mysql 字段類(lèi)型為json,后端用list接收

    board` json DEFAULT NULL COMMENT \\\'信息,格式[{\\\"name\\\":\\\"net\\\",\\\"chip\\\":\\\"esp32\\\",\\\"hdVer\\\":1}]\\\' resultMap id=\\\"productDeviceAndBrand\\\" type=\\\"com.charg.product.domain.vo.ProductDeviceOperationsVo\\\" result property=\\\"brandId\\\" column=\\\"brand_id\\\"/ result property=\\\"brandName\\\" column=\\\"brand_name\\\"/ result property=\\\"productName\\\" column=\\\"product_name\\\"/ result property=\\\"productC

    2024年04月09日
    瀏覽(18)
  • Postman發(fā)送post和get請(qǐng)求json數(shù)據(jù),并用SpringBoot接受

    Postman發(fā)送post和get請(qǐng)求json數(shù)據(jù),并用SpringBoot接受

    1. 在controller類(lèi)中加入如下代碼用于舉例 TestContoller.java 這里有兩個(gè)映射,一個(gè)是\\\"/test\\\",用于測(cè)試程序有沒(méi)有成功,一個(gè)是\\\"/User\\\",為用戶(hù),存放用戶(hù)的賬戶(hù)名和密碼 2. 在dto中導(dǎo)入數(shù)據(jù)以封裝數(shù)據(jù) TestDto.java @Data在導(dǎo)入lombok插件和依賴(lài)后可以直接使用,可以起到簡(jiǎn)化代碼的作用 在

    2023年04月09日
    瀏覽(17)
  • 前端向Java后端請(qǐng)求blob、arraybuffer類(lèi)型的數(shù)據(jù)流

    前端需要獲取后端音頻文件,但遇到跨域問(wèn)題,不能直接使用url獲取,需求必須使用流將文件傳到前端。因此,考慮Java后端讀取音頻文件,然后向前端發(fā)送數(shù)據(jù)流,前端按后端發(fā)送類(lèi)型將數(shù)據(jù)接收,并合成其格式文件。 引入axios.min.js文件 其中,responseType:‘a(chǎn)rraybuffer’,寫(xiě)成

    2024年02月13日
    瀏覽(25)
  • 【Spring】springmvc如何處理接受http請(qǐng)求

    【Spring】springmvc如何處理接受http請(qǐng)求

    目錄 ?編輯 1. 背景 2. web項(xiàng)目和非web項(xiàng)目 3. 環(huán)境準(zhǔn)備 4. 分析鏈路 5. 總結(jié) 今天開(kāi)了一篇文章“SpringMVC是如何將不同的Request路由到不同Controller中的?”;看完之后突然想到,在請(qǐng)求走到mvc 之前服務(wù)是怎么知道有請(qǐng)求進(jìn)來(lái)了,并且知道交給誰(shuí)處理呢?想看看這一塊的代碼 當(dāng)我

    2024年02月22日
    瀏覽(20)
  • SpringMVC | SpringMVC中的 “JSON數(shù)據(jù)交互“ 和 “RESTful設(shè)計(jì)風(fēng)格“

    SpringMVC | SpringMVC中的 “JSON數(shù)據(jù)交互“ 和 “RESTful設(shè)計(jì)風(fēng)格“

    作者簡(jiǎn)介 :一只大皮卡丘,計(jì)算機(jī)專(zhuān)業(yè)學(xué)生,正在努力學(xué)習(xí)、努力敲代碼中! 讓我們一起繼續(xù)努力學(xué)習(xí)! 該文章 參考學(xué)習(xí)教材 為: 《Java EE企業(yè)級(jí)應(yīng)用開(kāi)發(fā)教程 (Spring + Spring MVC +MyBatis)》 黑馬程序員 / 編著 文章以課本知識(shí)點(diǎn) + 代碼為主線(xiàn),結(jié)合自己看書(shū)學(xué)習(xí)過(guò)程中的理解和

    2024年04月10日
    瀏覽(31)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包