用户注册时出错
白标错误
This application has no explicit mapping for /error, so you are
seeing this as a fallback.
Wed Oct 24 16:46:26 IST 2018
There was an unexpected error (type=Bad Request, status=400).
Failed to convert value of type 'java.lang.String' to required type
'int'; nested exception is java.lang.NumberFormatException: For input string: ""
有两种形式的登记和办公
注册(用户)
@Entity
@Table(name="mytable")
public class User {
@Id
private int id; //Primary key
private String name;
private String mobile;
private String email;
private String college;
private String branch;
private String semester;
private String address;
private String internship;
private String batch;
private String startdate;
private String enddate;
//getters and setters
办公室
@Entity
@Table(name="officeinfo")
public class Office {
@Id
private int sno;
private String batchno;
private int id;
private String fees;
private String reciptno;
private String trainer;
//getters and setters
注册中的会话实现,以便填写(office的)id值
@PostMapping("/save-user")
public String registerUser(@ModelAttribute User user, BindingResult
bindingResult, HttpServletRequest request,HttpSession
session,@RequestParam("id") int id) {
userService.saveMyUser(user);
session.setAttribute("id", id);
int x = user.getId();
request.setAttribute("mode", "MODE_HOME");
return "welcomepage";
}
id的office页面jsp
<div class="form-group">
<label class="control-label col-md-3">Candidate
Registe rNumber</label>
<div class="col-md-5">
<input type="text" class="form-control
placeholder="Enter Register Number"
name="id" required value="${sessionScope.id }" />
</div>
</div>
/项目概念/
一旦用户注册的(值将存储在数据库中),他的id应该自动填写在office窗体页,并保存在数据库中使用会话的概念,但我得到这个错误请帮助!
2条答案
按热度按时间nbnkbykc1#
根据错误
需要整数值,但应用程序获取空字符串值。这就是为什么它会出错。我建议你用
Integer
类而不是int
. 我是说int id
至Integer id
. 我认为在这篇声明中session.setAttribute("id", id);
id的值没有设置。所以我建议你更换session.setAttribute("id", id);
至session.setAttribute("id", user.getId());
wswtfjt72#
解决方案是将user和office中的int都改为integer,并为user中的id包含“@generatedvalue(strategy=generationtype.identity)”。
办公室
在控制器中