NutzCN Logo
问答 spring mvc 参数封装不上
发布于 12天前 作者 qq_a56f9d68 78 次浏览 复制 上一个帖子 下一个帖子
标签:

入口函数:

    @ResponseBody
    @RequestMapping(value = "/updateUserRole", method = RequestMethod.POST)
    @RequiresPermissions("system:updateRolePermission")
    public Map<String, Object> updateUserRole(@RequestBody UserRoleVO userRoleVO) {
        Map<String, Object> map = new HashMap<String, Object>(0);
        try {
            //map.put("code", userRoleService.updateUserRoleById(userRoleVO));
            map.put("code", "1");
            return map;
        } catch (Exception e) {
            map.put("code", null);
            return map;
        }
    }

UserRoleVO


/** * @author iyayu (613163851@qq.com) * @version 1.0 * <p> * Description: 用户角色 视图对象 */ @JsonIgnoreProperties(value = {"handler"}) public class UserRoleVO extends UserRoleDO { private Integer page; private Integer limit; private List<UserPermissionVO> userPermissions = new ArrayList<UserPermissionVO>(); private List<String> test ; public List<String> getTest() { return test; } public void setTest(List<String> test) { this.test = test; } public List<UserPermissionVO> getUserPermissions() { return userPermissions; } public void setUserPermissions(List<UserPermissionVO> userPermissions) { this.userPermissions = userPermissions; } public Integer getPage() { return page; } public void setPage(Integer page) { this.page = page; } public Integer getLimit() { return limit; } public void setLimit(Integer limit) { this.limit = limit; } @Override public String toString() { return "UserRoleVO{" + "page=" + page + ", limit=" + limit + '}'; } }

UserRoleVO 里的 UserPermissionVO

public class UserPermissionVO extends UserPermissionDO {

    @Override
    public String toString() {
        return "UserPermissionVO{}";
    }
}
package cc.iyayu.basics.DO;

import java.io.Serializable;

/**
 * @author iyayu (613163851@qq.com)
 * @version 1.0
 *
 * Description: user_permission
 */
public class UserPermissionDO implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 主键
     * user_permission.id
     */
    private String id;

    /**
     * 资源名称
     * user_permission.name
     */
    private String name;

    /**
     * 资源类型:menu,button,
     * user_permission.type
     */
    private String type;

    /**
     * 访问url地址
     * user_permission.url
     */
    private String url;

    /**
     * 权限代码字符串
     * user_permission.percode
     */
    private String percode;

    /**
     * 父结点id
     * user_permission.parentid
     */
    private String parentid;

    /**
     * 排序号
     * user_permission.sortstring
     */
    private Long sortstring;

    /**
     * 图标
     * user_permission.icon
     */
    private String icon;

    /**
     * 说明
     * user_permission.describe
     */
    private String describe;

    /**
     * 是否可用,1:可用,0不可用
     * user_permission.available
     */
    private String available;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getPercode() {
        return percode;
    }

    public void setPercode(String percode) {
        this.percode = percode;
    }

    public String getParentid() {
        return parentid;
    }

    public void setParentid(String parentid) {
        this.parentid = parentid;
    }

    public Long getSortstring() {
        return sortstring;
    }

    public void setSortstring(Long sortstring) {
        this.sortstring = sortstring;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public String getDescribe() {
        return describe;
    }

    public void setDescribe(String describe) {
        this.describe = describe;
    }

    public String getAvailable() {
        return available;
    }

    public void setAvailable(String available) {
        this.available = available;
    }


    @Override
    public String toString() {
        return super.toString();
    }
}

页面:

 $.ajax({
            url: '/backstage/userRole/updateUserRole.do',
            type: 'POST',
            timeout: 15000,
            dataType: 'json',
//            contentType: "application/json;charset=utf-8",
            data:
                {
                id: $("#roleId").val(),
                name: $("#textName").val(),
                describe: $("#textDescribe").val(),
                    userPermissions:[{id: 'asd', name: "23123"}]
            },
            beforeSend: function (XMLHttpRequest) {
                index = layer.load(2, {shade: false});
            },
            success: function (data) {
                layer.close(index);
                if (data['code'] == null || data['code'] == 'null') {
                    layer.msg('更新失败');
                } else {
                    console.log(data);

                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.msg('请求数据失败, 请检查网络连接.');
                layer.close(index);
            }
        });

错误日志:

[DEBUG] 2017-12-05 16:02:24,499 method:org.apache.shiro.web.servlet.SimpleCookie.readValue(SimpleCookie.java:389) ==> Found 'jsid' cookie value [2d4195f3-8f9a-4047-ad19-c13a8c25a048]
[DEBUG] 2017-12-05 16:02:24,500 method:org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:865) ==> DispatcherServlet with name 'SpringMVC' processing POST request for [/backstage/userRole/updateUserRole.do]
[DEBUG] 2017-12-05 16:02:24,500 method:org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.getHandlerInternal(AbstractHandlerMethodMapping.java:310) ==> Looking up handler method for path /backstage/userRole/updateUserRole.do
[DEBUG] 2017-12-05 16:02:24,501 method:org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.getHandlerInternal(AbstractHandlerMethodMapping.java:317) ==> Returning handler method [public java.util.Map<java.lang.String, java.lang.Object> cc.iyayu.basics.controller.UserRoleController.updateUserRole(cc.iyayu.basics.vo.UserRoleVO)]
[DEBUG] 2017-12-05 16:02:24,502 method:org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:251) ==> Returning cached instance of singleton bean 'userRoleController'
[DEBUG] 2017-12-05 16:02:24,519 method:org.springframework.web.cors.DefaultCorsProcessor.processRequest(DefaultCorsProcessor.java:77) ==> Skip CORS processing: request is from same origin
[DEBUG] 2017-12-05 16:02:24,527 method:org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:164) ==> Failed to resolve argument 0 of type 'cc.iyayu.basics.vo.UserRoleVO'
org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported
	at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:237)
	at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.readWithMessageConverters(RequestResponseBodyMethodProcessor.java:150)
	at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:128)
	at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:121)
	at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:158)
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:128)
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)
	at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
	at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
	at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
	at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
	at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
	at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
	at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:387)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
	at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
	at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:475)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:498)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:796)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1366)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:748)
[DEBUG] 2017-12-05 16:02:24,533 method:org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver.resolveException(AbstractHandlerExceptionResolver.java:133) ==> Resolving exception from handler [public java.util.Map<java.lang.String, java.lang.Object> cc.iyayu.basics.controller.UserRoleController.updateUserRole(cc.iyayu.basics.vo.UserRoleVO)]: org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported
[DEBUG] 2017-12-05 16:02:24,543 method:org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver.resolveException(AbstractHandlerExceptionResolver.java:133) ==> Resolving exception from handler [public java.util.Map<java.lang.String, java.lang.Object> cc.iyayu.basics.controller.UserRoleController.updateUserRole(cc.iyayu.basics.vo.UserRoleVO)]: org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported
[DEBUG] 2017-12-05 16:02:24,544 method:org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver.resolveException(AbstractHandlerExceptionResolver.java:133) ==> Resolving exception from handler [public java.util.Map<java.lang.String, java.lang.Object> cc.iyayu.basics.controller.UserRoleController.updateUserRole(cc.iyayu.basics.vo.UserRoleVO)]: org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported
[DEBUG] 2017-12-05 16:02:24,547 method:org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1044) ==> Null ModelAndView returned to DispatcherServlet with name 'SpringMVC': assuming HandlerAdapter completed request handling
[DEBUG] 2017-12-05 16:02:24,547 method:org.mybatis.spring.SqlSessionUtils.getSqlSession(SqlSessionUtils.java:97) ==> Creating a new SqlSession
[DEBUG] 2017-12-05 16:02:24,549 method:org.mybatis.spring.SqlSessionUtils.registerSessionHolder(SqlSessionUtils.java:128) ==> Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@c07d345]
[DEBUG] 2017-12-05 16:02:24,550 method:org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:110) ==> Fetching JDBC Connection from DataSource
[DEBUG] 2017-12-05 16:02:24,550 method:org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:114) ==> Registering transaction synchronization for JDBC Connection
[DEBUG] 2017-12-05 16:02:24,552 method:org.mybatis.spring.transaction.SpringManagedTransaction.openConnection(SpringManagedTransaction.java:87) ==> JDBC Connection [jdbc:mysql://127.0.0.1:3306/basics_database?useUnicode=true&characterEncoding=UTF8&autoReconnect=true&failOverReadOnly=false&allowMultiQueries=true, UserName=root@localhost, MySQL Connector Java] will be managed by Spring
[DEBUG] 2017-12-05 16:02:24,552 method:org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:159) ==> ==>  Preparing: INSERT INTO system_logInfo ( id, userAccountId, requestUrl, requestParameter, responseParameter, successOrFailure, referer, userAgent, errorInfo ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ? ) 
[DEBUG] 2017-12-05 16:02:24,554 method:org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:159) ==> ==> Parameters: 4a318a0c539943e39fde3648809cfcfa(String), 30ffa394be4d11e7a0dd1c75086c29d6(String), http://localhost:8080/backstage/userRole/updateUserRole.do(String), {"describe":["拥有平台所有权限, 千万不要泄露"],"id":["ebc8a441c6f911e4b1370adc305c3f28"],"name":["超级管理员"],"userPermissions[0][id]":["asd"],"userPermissions[0][name]":["23123"]}(String), {}(String), 1(String), http://localhost:8080/backstage/userRole/rolePermissionById.html?id=ebc8a441c6f911e4b1370adc305c3f28&action=edit(String), Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36(String), (String)
[DEBUG] 2017-12-05 16:02:24,601 method:org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:159) ==> <==    Updates: 1
[DEBUG] 2017-12-05 16:02:24,602 method:org.mybatis.spring.SqlSessionUtils.closeSqlSession(SqlSessionUtils.java:186) ==> Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@c07d345]
[DEBUG] 2017-12-05 16:02:24,602 method:org.mybatis.spring.SqlSessionUtils$SqlSessionSynchronization.beforeCompletion(SqlSessionUtils.java:310) ==> Transaction synchronization deregistering SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@c07d345]
[DEBUG] 2017-12-05 16:02:24,602 method:org.mybatis.spring.SqlSessionUtils$SqlSessionSynchronization.beforeCompletion(SqlSessionUtils.java:315) ==> Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@c07d345]
[DEBUG] 2017-12-05 16:02:24,603 method:org.springframework.jdbc.datasource.DataSourceUtils.doReleaseConnection(DataSourceUtils.java:327) ==> Returning JDBC Connection to DataSource
[DEBUG] 2017-12-05 16:02:24,603 method:org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1000) ==> Successfully completed request

十分纠结,搞了好久也没搞好,抱着试试看的心态来社区提问(蛋蛋。。)

14 回复

就没加

data : JSON.stringify({........}) 

发json就好啦

我是这个错误撒。。。。

method:org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:164) ==> Failed to resolve argument 0 of type 'cc.iyayu.basics.vo.UserRoleVO'
org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported

刚才加上了也没用。。。

Request URL:http://localhost:8080/backstage/userRole/updateUserRole.do
Request Method:POST
Status Code:415 
Remote Address:[::1]:8080
Referrer Policy:no-referrer-when-downgrade
POST /backstage/userRole/updateUserRole.do HTTP/1.1
Host: localhost:8080
Connection: keep-alive
Content-Length: 300
Accept: application/json, text/javascript, */*; q=0.01
Origin: http://localhost:8080
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Referer: http://localhost:8080/backstage/userRole/rolePermissionById.html?id=ebc8a441c6f911e4b1370adc305c3f28&action=edit
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.8
Cookie: jsid=2d4195f3-8f9a-4047-ad19-c13a8c25a048; JSESSIONID=12A3784470D0675599B3035B3E3D948D

额,没发过json数据??

data : JSON.stringify({........}),
contentType : "application/json"

发了,好像封装失败了

[DEBUG] 2017-12-05 16:11:47,197 method:org.apache.shiro.web.servlet.SimpleCookie.readValue(SimpleCookie.java:389) ==> Found 'jsid' cookie value [2d4195f3-8f9a-4047-ad19-c13a8c25a048]
[DEBUG] 2017-12-05 16:11:47,201 method:org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:865) ==> DispatcherServlet with name 'SpringMVC' processing POST request for [/backstage/userRole/updateUserRole.do]
[DEBUG] 2017-12-05 16:11:47,202 method:org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.getHandlerInternal(AbstractHandlerMethodMapping.java:310) ==> Looking up handler method for path /backstage/userRole/updateUserRole.do
[DEBUG] 2017-12-05 16:11:47,202 method:org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.getHandlerInternal(AbstractHandlerMethodMapping.java:317) ==> Returning handler method [public java.util.Map<java.lang.String, java.lang.Object> cc.iyayu.basics.controller.UserRoleController.updateUserRole(cc.iyayu.basics.vo.UserRoleVO)]
[DEBUG] 2017-12-05 16:11:47,203 method:org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:251) ==> Returning cached instance of singleton bean 'userRoleController'
[DEBUG] 2017-12-05 16:11:47,203 method:org.springframework.web.cors.DefaultCorsProcessor.processRequest(DefaultCorsProcessor.java:77) ==> Skip CORS processing: request is from same origin
[DEBUG] 2017-12-05 16:11:47,204 method:org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:197) ==> Read [class cc.iyayu.basics.vo.UserRoleVO] as "application/json;charset=UTF-8" with [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@12015aa4]
[DEBUG] 2017-12-05 16:11:47,204 method:org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:164) ==> Failed to resolve argument 0 of type 'cc.iyayu.basics.vo.UserRoleVO'
org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON document: Unrecognized token 'id': was expecting ('true', 'false' or 'null')
 at [Source: (PushbackInputStream); line: 1, column: 4]; nested exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'id': was expecting ('true', 'false' or 'null')
 at [Source: (PushbackInputStream); line: 1, column: 4]
	at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:234)
	at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.read(AbstractJackson2HttpMessageConverter.java:219)
	at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:201)
	at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.readWithMessageConverters(RequestResponseBodyMethodProcessor.java:150)
	at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:128)
	at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:121)
	at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:158)
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:128)
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)
	at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
	at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
	at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
	at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
	at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
	at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
	at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:387)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
	at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
	at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:475)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:498)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:796)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1366)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:748)
Caused by: com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'id': was expecting ('true', 'false' or 'null')
 at [Source: (PushbackInputStream); line: 1, column: 4]
	at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1771)
	at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:661)
	at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._reportInvalidToken(UTF8StreamJsonParser.java:3521)
	at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._handleUnexpectedValue(UTF8StreamJsonParser.java:2682)
	at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._nextTokenNotInObject(UTF8StreamJsonParser.java:875)
	at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.nextToken(UTF8StreamJsonParser.java:769)
	at com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:4073)
	at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3984)
	at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3060)
	at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:231)
	... 60 more
[DEBUG] 2017-12-05 16:11:47,215 method:org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver.resolveException(AbstractHandlerExceptionResolver.java:133) ==> Resolving exception from handler [public java.util.Map<java.lang.String, java.lang.Object> cc.iyayu.basics.controller.UserRoleController.updateUserRole(cc.iyayu.basics.vo.UserRoleVO)]: org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON document: Unrecognized token 'id': was expecting ('true', 'false' or 'null')
 at [Source: (PushbackInputStream); line: 1, column: 4]; nested exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'id': was expecting ('true', 'false' or 'null')
 at [Source: (PushbackInputStream); line: 1, column: 4]
[DEBUG] 2017-12-05 16:11:47,216 method:org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver.resolveException(AbstractHandlerExceptionResolver.java:133) ==> Resolving exception from handler [public java.util.Map<java.lang.String, java.lang.Object> cc.iyayu.basics.controller.UserRoleController.updateUserRole(cc.iyayu.basics.vo.UserRoleVO)]: org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON document: Unrecognized token 'id': was expecting ('true', 'false' or 'null')
 at [Source: (PushbackInputStream); line: 1, column: 4]; nested exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'id': was expecting ('true', 'false' or 'null')
 at [Source: (PushbackInputStream); line: 1, column: 4]
[DEBUG] 2017-12-05 16:11:47,216 method:org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver.resolveException(AbstractHandlerExceptionResolver.java:133) ==> Resolving exception from handler [public java.util.Map<java.lang.String, java.lang.Object> cc.iyayu.basics.controller.UserRoleController.updateUserRole(cc.iyayu.basics.vo.UserRoleVO)]: org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON document: Unrecognized token 'id': was expecting ('true', 'false' or 'null')
 at [Source: (PushbackInputStream); line: 1, column: 4]; nested exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'id': was expecting ('true', 'false' or 'null')
 at [Source: (PushbackInputStream); line: 1, column: 4]
[WARN ] 2017-12-05 16:11:47,216 method:org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver.handleHttpMessageNotReadable(DefaultHandlerExceptionResolver.java:384) ==> Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON document: Unrecognized token 'id': was expecting ('true', 'false' or 'null')
 at [Source: (PushbackInputStream); line: 1, column: 4]; nested exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'id': was expecting ('true', 'false' or 'null')
 at [Source: (PushbackInputStream); line: 1, column: 4]
[DEBUG] 2017-12-05 16:11:47,222 method:org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1044) ==> Null ModelAndView returned to DispatcherServlet with name 'SpringMVC': assuming HandlerAdapter completed request handling
[DEBUG] 2017-12-05 16:11:47,223 method:org.mybatis.spring.SqlSessionUtils.getSqlSession(SqlSessionUtils.java:97) ==> Creating a new SqlSession
[DEBUG] 2017-12-05 16:11:47,223 method:org.mybatis.spring.SqlSessionUtils.registerSessionHolder(SqlSessionUtils.java:128) ==> Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@39a8dd6d]
[DEBUG] 2017-12-05 16:11:47,224 method:org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:110) ==> Fetching JDBC Connection from DataSource
[DEBUG] 2017-12-05 16:11:47,224 method:org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:114) ==> Registering transaction synchronization for JDBC Connection
[DEBUG] 2017-12-05 16:11:47,225 method:org.mybatis.spring.transaction.SpringManagedTransaction.openConnection(SpringManagedTransaction.java:87) ==> JDBC Connection [jdbc:mysql://127.0.0.1:3306/basics_database?useUnicode=true&characterEncoding=UTF8&autoReconnect=true&failOverReadOnly=false&allowMultiQueries=true, UserName=root@localhost, MySQL Connector Java] will be managed by Spring
[DEBUG] 2017-12-05 16:11:47,225 method:org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:159) ==> ==>  Preparing: INSERT INTO system_logInfo ( id, userAccountId, requestUrl, requestParameter, responseParameter, successOrFailure, referer, userAgent, errorInfo ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ? ) 
[DEBUG] 2017-12-05 16:11:47,226 method:org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:159) ==> ==> Parameters: 18a199eaf26949c99b120d0f5f6a1330(String), 30ffa394be4d11e7a0dd1c75086c29d6(String), http://localhost:8080/backstage/userRole/updateUserRole.do(String), {}(String), {}(String), 1(String), http://localhost:8080/backstage/userRole/rolePermissionById.html?id=ebc8a441c6f911e4b1370adc305c3f28&action=edit(String), Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36(String), (String)
[DEBUG] 2017-12-05 16:11:47,274 method:org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:159) ==> <==    Updates: 1
[DEBUG] 2017-12-05 16:11:47,275 method:org.mybatis.spring.SqlSessionUtils.closeSqlSession(SqlSessionUtils.java:186) ==> Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@39a8dd6d]
[DEBUG] 2017-12-05 16:11:47,275 method:org.mybatis.spring.SqlSessionUtils$SqlSessionSynchronization.beforeCompletion(SqlSessionUtils.java:310) ==> Transaction synchronization deregistering SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@39a8dd6d]
[DEBUG] 2017-12-05 16:11:47,292 method:org.mybatis.spring.SqlSessionUtils$SqlSessionSynchronization.beforeCompletion(SqlSessionUtils.java:315) ==> Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@39a8dd6d]
[DEBUG] 2017-12-05 16:11:47,292 method:org.springframework.jdbc.datasource.DataSourceUtils.doReleaseConnection(DataSourceUtils.java:327) ==> Returning JDBC Connection to DataSource
[DEBUG] 2017-12-05 16:11:47,292 method:org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1000) ==> Successfully completed request

携带参数是这样的:

id=ebc8a441c6f911e4b1370adc305c3f28&name=%E8%B6%85%E7%BA%A7%E7%AE%A1%E7%90%86%E5%91%98&describe=%E6%8B%A5%E6%9C%89%E5%B9%B3%E5%8F%B0%E6%89%80%E6%9C%89%E6%9D%83%E9%99%90%2C%20%E5%8D%83%E4%B8%87%E4%B8%8D%E8%A6%81%E6%B3%84%E9%9C%B2&userPermissions=%5B%7B%22id%22%3A%22asd%22%2C%22name%22%3A%2223123%22%7D%5D

js代码贴一下看看

  var temp = JSON.stringify(_list);
        var index; //加载层
        var userPermissions = new Array();
        userPermissions.push('12354');
        userPermissions.push('456132');
        $.ajax({
            url: '/backstage/userRole/updateUserRole.do',
            type: 'POST',
            timeout: 15000,
            dataType: 'json',
           contentType : "application/json",
            data:
                {
                id: $("#roleId").val(),
                name: $("#textName").val(),
                describe: $("#textDescribe").val(),
                    userPermissions: JSON.stringify([{id: 'asd', name: "23123"}])
            },
            beforeSend: function (XMLHttpRequest) {
                index = layer.load(2, {shade: false});
            },
            success: function (data) {
                layer.close(index);
                if (data['code'] == null || data['code'] == 'null') {
                    layer.msg('更新失败');
                } else {
                    console.log(data);

                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.msg('请求数据失败, 请检查网络连接.');
                layer.close(index);
            }
        });
contentType : "application/json",
data: JSON.stringify({
                id: $("#roleId").val(),
                name: $("#textName").val(),
                describe: $("#textDescribe").val(),
                userPermissions: [{id: 'asd', name: "23123"}]
            })

问题已解决,感谢wendal大叔 O(∩_∩)O

@qq_a56f9d68 nutz 欢迎你^_^

问题已解决,感谢wendal大叔 O(∩_∩)O

添加回复
请先登陆
回到顶部