【发布时间】:2018-08-06 08:29:42
【问题描述】:
当我选择多个复选框以保存在数据库中时,它会显示错误,当我没有选择任何框时,只需写入组名,它将名称保存在数据库中。
GroupDetail.java
package com.userauthenticate.model;
import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;
@Entity
public class GroupDetail {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
private String groupName;
@ManyToMany
private Set<UserDetail> user= new HashSet<UserDetail>();
@OneToMany
private Set<Role> role= new HashSet<Role>();
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getGroupName() {
return groupName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
public Set<UserDetail> getUser() {
return user;
}
public void setUser(Set<UserDetail> user) {
this.user = user;
}
public Set<Role> getRole() {
return role;
}
public void setRole(Set<Role> role) {
this.role = role;
}
}
GroupController.java
package com.userauthenticate.controller;
import com.userauthenticate.model.GroupDetail;
import com.userauthenticate.service.GroupDetailService;
import com.userauthenticate.service.RoleService;
import com.userauthenticate.service.UserDetailService;
import org.hibernate.annotations.Parameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class GroupController {
@Autowired
private GroupDetailService groupDetailService;
@Autowired
private RoleService roleService;
@Autowired
private UserDetailService userDetailService;
private String msg = "namme in group";
@RequestMapping("grouplist")
public ModelAndView grouplist() {
ModelAndView modelAndView = new ModelAndView("grouplists");
modelAndView.addObject("message", msg);
modelAndView.addObject("grouplist", groupDetailService.getGrouplist());
modelAndView.addObject("rolelist", roleService.getRolelist());
modelAndView.addObject("userlist", userDetailService.getUserList());
modelAndView.addObject("group", new GroupDetail());
return modelAndView;
}
@RequestMapping(value = "/addgroup", method = RequestMethod.POST)
public ModelAndView addgroup(@ModelAttribute("group") GroupDetail group) {
// System.out.println(333);
System.out.println(group.getGroupName());
groupDetailService.add(group);
return new ModelAndView("redirect:/grouplist");
}
}
Grouplists.jsp
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form"
uri="http://www.springframework.org/tags/form" %>
<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-
8859-1" />
<title>Home</title>
</head>
<body>
<h1>Welcome, ${message}</h1> <a href="/">LogOut</a>
<table>
<tbody>
<form:form action="/addgroup" method="post" modelAttribute="group">
<tr>
<td>Group Name</td>
<td><form:input type="text" name="eee" path="groupName"/></td>
</tr>
<tr>
<td>Role</td>
<td>
<%--<form:checkboxes path="role" items="${rolelist}" itemValue="${rolelist.id}"/>--%>
<c:forEach items="${rolelist}" var="r">
<form:checkbox value="${r.id}" path="role"/> ${r.role}
</c:forEach>
</td>
</tr>
<tr>
<td>Users</td>
<td>
<c:forEach items="${userlist}" var="u">
<form:checkbox value="${u.email}" path="user"/> ${u.name}(${u.email})
</c:forEach>
</td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" value="Add"/>
</td>
</tr>
</form:form>
</tbody>
</table>
</body>
</html>
错误:
400- Bad Request 服务器不能或不会处理到期的请求 被认为是客户错误的东西(例如,格式错误 请求语法、无效请求消息帧或欺骗性请求 路由)。
【问题讨论】:
标签: java spring hibernate maven spring-boot