入口函数:
@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
十分纠结,搞了好久也没搞好,抱着试试看的心态来社区提问(蛋蛋。。)