-1

I use an url to request a controller in browser directly, but I get '{}' an empty object . I'm sure the controller's return not empty, but the page get an empty response.

I also build a new project with the working config file from a working project, but in the new project still get a empty response after request.

I don't know reason, anything is the same with the working project.

code follow.

controller,just a simple test

  @Controller
  @RequestMapping("/layout")  
  public class LayoutController {

    @Autowired
    LayoutServer layoutServer;

    @RequestMapping("/test1")
    @ResponseBody
    public ResultUtil test(){
        ResultUtil resultUtil=ResultUtil.success(200,"this is data","this is page data");
        System.out.println(resultUtil);
        return resultUtil;
    }
  }

the request result, sorry upload picture failure. It's only get '{}'. the console print is working normal

config follow.

spring-mvc.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
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">

<!--启用spring的一些annotation -->
<context:annotation-config/>
<!--注册驱动-->
<mvc:annotation-driven>
    <mvc:message-converters register-defaults="true">
        <!-- 配置Fastjson支持 -->
        <bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
            <property name="supportedMediaTypes">
                <list>
                    <value>application/json;charset=UTF-8</value>
                </list>
            </property>
            <property name="features">
                <list>
                    <value>WriteDateUseDateFormat</value>
                    <value>QuoteFieldNames</value>
                </list>
            </property>
        </bean>
        <bean class="org.springframework.http.converter.StringHttpMessageConverter">
            <property name="supportedMediaTypes">
                <list><value>text/html;charset=UTF-8</value></list>
            </property>
        </bean>
    </mvc:message-converters>
</mvc:annotation-driven>

<context:component-scan base-package="com.drawdemo.controller">
    <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/jsp/"/>
    <property name="suffix" value=".jsp"/>
</bean>

<bean id="multipartResolver"
      class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
    <property name="defaultEncoding" value="utf-8"/>
    <property name="maxUploadSize" value="10485760000"/>
    <property name="maxInMemorySize" value="40960"/>
</bean>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
      http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
     version="3.0">

<display-name>Archetype Created Web Application</display-name>

<!-- Spring字符集过滤器 -->
<filter>
  <filter-name>SpringEncodingFilter</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>
  <init-param>
    <param-name>forceEncoding</param-name>
    <param-value>true</param-value>
  </init-param>
</filter>
<filter-mapping>
  <filter-name>SpringEncodingFilter</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>

<!--spring和mybatis的配置文件-->
<context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>classpath:/config/spring-mybatis.xml</param-value>
</context-param>

<!--spring监听器-->
<listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!--防止spring内存溢出监听器-->
<listener>
  <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>

<!-- springMVC核心配置 -->
<servlet>
  <servlet-name>spring</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet- 
class>
  <init-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
      classpath:config/spring-mvc.xml
    </param-value>
  </init-param>
  <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
  <servlet-name>spring</servlet-name>
  <url-pattern>/</url-pattern>
</servlet-mapping>

ggunlics
  • 1
  • 1

1 Answers1

0

I got the anwser.

there is no getter/setter with ResultUtil (the response data).It took a day,fxxxxxxxk.

In beginning ,I print the ResultUtil on the console ,it's show natural ,so I think it natural and check the config.

A short while ago, I check all the file with error project and working project again ,notice that no getter/setter ,add it and run, it's working.

ggunlics
  • 1
  • 1