SSM遇到的问题(四)

278 阅读1分钟

1. ajax请求错误:$.get is not a function

JQuery: $.get is not a function

解决:

<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js"></script>

改成

<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>

额外扩展:

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">

现在的boostrap的引用中多了integritycrossorigin两个属性,了解一下,作用是什么?

What are the integrity and crossorigin attributes?

大概就是,引入两个属性,保证资源的完整性。也可以不引用。

2.SSM的页面有ajax请求返回数据,返回失败。

提示:返回的类型对象无法转换成json输出。


  1. Failed to write HTTPmessage:org.springframework.http.converter.HttpMessageNotWritableException: No

  2. java.lang.IllegalArgumentException: No converter found for return value of type

    由此了解到要想输出转换成为json对象,要保证类型的字段属性,都有开放(public)的getter/setter


  1. Failed to write HTTP message: org.springframework.http.converter.HttpMessageNotWritableException: Co

    由此了解到,如果转换的类型中有些字段不需要生成时,可以使用 @JsonIgnoreProperties() 来忽略生成json对象的属性。


  1. SpringMVC返回对象类型报错HttpMessageNotWritableException: No converter found for return value of type

    json配置

    <!--fastjson的配置-->
        <mvc:annotation-driven>
            <mvc:message-converters>
                <bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
                    <property name="supportedMediaTypes" value="application/json;charset=utf-8"/>
                </bean>
            </mvc:message-converters>
        </mvc:annotation-driven>
    

    解决:很尴尬,因为没有进行配置,所以出现,无法转换json对象的错误。