java - 如何从组合键中设置和获取值
问题描述
我正在尝试使用
如何在我的控制器中设置和获取值来设置cid
学生类中的值。SubjectMark->private String cid;
实体和控制器方法如下:
@Entity
public class Student implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
private SubjectMark id;
private String fullName;
private Integer totalMarks;
private Double percentage;
private String grade;
//Setters and getters
}
//Composit class
@Embeddable
public class SubjectMark implements Serializable {
//Composit key
private String cid;
//Setters and getters
}
在我的控制器中,我尝试像这样设置值:
@RequestMapping(value="getstdata",method=RequestMethod.GET)
@ResponseBody
public String getstdata(@RequestParam(value="cid")String cid){
//Some code
try{
Student st=new Student();
st.getId().setCid(cid);//Set value like this but it is getting null pointer exception
//some code
//retuen some value
}
请帮我!
解决方案
我猜你需要在你的类中编写一个get set方法......尝试编写类似的东西
私人字符串 cid;
公共字符串 Cid { 获取 => cid; 设置 => cid = 值;}
推荐阅读
- chart.js - 具有多个条形和 1 个标签的条形图
- python - 无法使用 Pandas 写入具有有效日期格式的 Excel 工作表
- bash - 浏览历史时 Bash 提示错误
- php - 在 Angular 8 中未接收到整个 JSON 有效负载
- php - 根据主标题单击子 div
- python - 打印 Python 上的额外新行
- apache-spark - pyspark Column 不可使用 withColumn 进行迭代
- luigi - 如何使用上游任务的输出来驱动 requires() 的结果?
- java - 数组位置中的一些“隐藏”错误(可能)
- google-apps-script - 如何根据下拉值将行复制到另一张表?