- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我是 Spring MVC 的新手。我开发了一个示例应用程序,它执行 SELECT、INSERT、UPDATE 和 DELETE。
下面是我的 Bean 类
@Id
@Column
private int student_id;
private String name;
private String age;
private String city;
private String country;
private Integer phone;
private int hsc;
private int sslc;
private int college;
/*getter and setters*/
下面是我的 Controller 类
@Controller
public class StudentController {
private static final Logger logger = Logger.getLogger(StudentController.class);
@Autowired
private StudentService studentService;
@RequestMapping(value = "/students", method = RequestMethod.GET)
public String listStudents(Model model){
if(logger.isDebugEnabled()){
logger.debug("listStudents method is executed!");
}
logger.error("This is an error message", new Exception("Testing"));
model.addAttribute("student", new StudentDO());
model.addAttribute("listStudents", this.studentService.listStudents());
return "students";
}
@RequestMapping(value = "/students/add", method = RequestMethod.POST)
public String addStudent(@ModelAttribute("student") StudentDO studentDO){
if(studentDO.getStudent_id() == 0){
/**new person, add it*/
this.studentService.addStudent(studentDO);
}else{
/**existing person, call update*/
this.studentService.updateStudent(studentDO);
}
return "redirect:/students";
}
}
下面是我的JSP页面
<c:url var="addAction" value="/students/add" ></c:url>
<form:form action="${addAction}" commandName="student">
<table>
<c:if test="${!empty student.name}">
<tr>
<td>
<form:label path="student_id">
<spring:message text="STUDENT_ID"/>
</form:label>
</td>
<td>
<form:input path="student_id" readonly="true" size="8" disabled="true" />
<form:hidden path="student_id" />
</td>
</tr>
</c:if>
<tr>
<td>
<form:label path="name">
<spring:message text="Name"/>
</form:label>
</td>
<td>
<form:input path="name" />
</td>
</tr>
<tr>
<td>
<form:label path="age">
<spring:message text="Age"/>
</form:label>
</td>
<td>
<form:input path="age" />
</td>
</tr>
<tr>
<td>
<form:label path="city">
<spring:message text="City"/>
</form:label>
</td>
<td>
<form:input path="city" />
</td>
</tr>
<tr>
<td>
<form:label path="country">
<spring:message text="Country"/>
</form:label>
</td>
<td>
<form:input path="country" />
</td>
</tr>
<tr>
<td>
<form:label path="phone">
<spring:message text="Phone"/>
</form:label>
</td>
<td>
<form:input path="phone" />
</td>
</tr>
<tr>
<td>
<form:label path="hsc">
<spring:message text="HSC"/>
</form:label>
</td>
<td>
<form:input path="hsc" />
</td>
</tr>
<tr>
<td>
<form:label path="sslc">
<spring:message text="SSLC"/>
</form:label>
</td>
<td>
<form:input path="sslc" />
</td>
</tr>
<tr>
<td>
<form:label path="college">
<spring:message text="College"/>
</form:label>
</td>
<td>
<form:input path="college" />
</td>
</tr>
<tr>
<td colspan="2">
<c:if test="${!empty student.name}">
<input type="submit" value="<spring:message text="Edit Student"/>" />
</c:if>
<c:if test="${empty student.name}">
<input type="submit" value="<spring:message text="Add Student"/>" />
</c:if>
</td>
</tr>
现在面临两个问题。1. 输入值并单击“添加学生”按钮后,出现以下错误。
org.springframework.validation.BindException:
org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object 'student' on field 'phone': rejected value [9962287970];
codes [typeMismatch.student.phone,typeMismatch.phone,typeMismatch.java.lang.Integer,typeMismatch];
arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [student.phone,phone]; arguments [];
default message [phone]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.lang.Integer' for property 'phone';
nested exception is java.lang.NumberFormatException: For input string: "9962287970"]
最佳答案
问题是值 9962287970 超出类型 Integer
的范围。
Integer.MAX_VALUE < 9962287970
要解决此问题,请将 private Integer phone;
更改为 private Long phone;
或 private String phone;
如果您使用 String
,您可以将其他字符(例如 +
)存储到变量 phone
中。
引用http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html
int
的默认值是 0 但对于 Integer
它不是零,因为它是一个对象,所以你必须将值初始化为 0;
关于java - Spring MVC - 无法将类型 'java.lang.String' 的属性值转换为所需类型 'java.lang.Integer',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41058728/
我有一个加载有默认值的元素。后来,我通过 jQuery 的 input.val("different value") 更改了该值。 . 当我 console.log() 元素时,我在 firebug
我们在 DropDownListFor(ASP.NET MVC3 版本)中发现了奇怪的行为。它在下拉列表中选择 ViewBag 属性值而不是 Model 属性值。 模型: public class C
寻找一种方法将描述字段添加到 Magento 中的单个属性值。请注意,我指的是属性值选项,而不是实际的属性本身。 举个例子: 属性=颜色 属性值:红、绿、蓝 我想为 3 种颜色中的每一种添加一个描述字
我知道如果我们知道注释类,我们可以轻松获取特定的注释并访问其属性。例如: field.getAnnotation(Class annotationClass) 它将返回特定注释接口(interface
我正在尝试报告我创建的椭圆形 div 的边框半径值,但我得到了一个未定义的返回值。谁能解释为什么?我是犯了一个简单的错误还是我的代码有问题?谢谢你! CSS3
我有两个表: Bike__________________________ Kiosk 带列: BikeID, Location_________________ KioskID,
我在 Java .properties 文件中有一个值需要以反冲结束。属性值应该是“\\server\folder\”,我这样输入值: name=\\\\server\\folder\\ 结尾的反斜杠
我创建了一个 DeformableShape 对象并通过 for 循环创建它的实例。我正在调用对象的 setPosition 方法并更改其枢轴属性,但所有实例的值都会更新...假设我有对象 A 并且我
是否可以在类名中为 CSS 传递参数?例如: .mrg-t-X { margin-top: Xpx; } Test 在此示例中,X 应为 10。 最佳答案 不,不是。我们最接近的是 attr()
是否可以在类名中为 CSS 传递参数?例如: .mrg-t-X { margin-top: Xpx; } Test 在此示例中,X 应为 10。 最佳答案 不,不是。我们最接近的是 attr()
是否可以在类名中为 CSS 传递参数?例如: .mrg-t-X { margin-top: Xpx; } Test 在此示例中,X 应为 10。 最佳答案 不,不是。我们最接近的是 attr()
我在使用 C# 中的数据注释时遇到了问题。我正在使用自定义必需属性和范围属性,我想将一个对象设置为错误消息。 [MyOwnRequired(ErrorCode=GlobalMessages.Messa
是否可以在类名中为 CSS 传递参数?例如: .mrg-t-X { margin-top: Xpx; } Test 在此示例中,X 应为 10。 最佳答案 不,不是。我们最接近的是 attr()
我知道如果我们知道注解类,我们可以很容易地得到具体的注解并访问它的属性。例如: field.getAnnotation(Class annotationClass) 这将返回特定注解接口(interf
我正在使用 sinon v4.1.2。根据文档( http://sinonjs.org/releases/v4.1.2/sandbox/ ),我应该能够使用以下内容设置属性: sandbox.stub
我想在我的应用程序中将一些 valraibles 的值外部化,它使用 spring 到类似属性文件的东西。 我怎样才能做到这一点? 最佳答案 Spring 提供了一个 BeanFactoryPostP
我有这个界面 public interface IMyInterface { IEnumerable Params { get; } } 在哪里 MyParamInfo 是 public c
我有一个 xml 字符串,其中包含我想要屏蔽的某些值。我还有一个黑名单列表,其中包含我要屏蔽的元素或属性的名称。我如何使用 Linq 执行此操作? var BlackList=new List{"ss
以下是读入XmlDocument的XML文件 我需要的是存储在一些 TextBox 中的 'id' 属性值(“2015”) 这就是 XmlDocument 的加载方式 XmlDocume
IDE 对象检查器通过下拉 ColorBox 显示 TColor 属性,并且可以按图形单元中定义的名称 - clBlack 等选择颜色。问题是图形单元中定义的 clWeb 颜色不存在,并且我定义的任何
我是一名优秀的程序员,十分优秀!