1.报一大段红错
此时对象还是能创建成功的,解决方案参考链接https://blog.csdn.net/wanglin199709/article/details/99121487
2.无法创建对象
原因:说明能进去sql数据库,那么问题一定是出在Java bean里的,一检查果不其然,没有添加get/set方法
1 package com.atguigu.demo.bean; 2 3 import javax.persistence.Column; 4 import javax.persistence.Id; 5 import javax.persistence.Table; 6 7 /** 8 * @author yangxu 9 * @version 1.0 10 * @date 2020/2/6 16:32 11 */ 12 @Table(name="employeesTest")//表示对应sql数据库中的哪个表 13 public class Employees { 14 @Id//主键 15 @Column//每个属性都需要有这个注释 16 private int id; 17 @Column 18 private String name; 19 @Column 20 private String sex; 21 22 public Employees(int id, String name, String sex) { 23 this.id = id; 24 this.name = name; 25 this.sex = sex; 26 } 27 28 public Employees() { 29 } 30 //get/set方法必须有 31 public int getId() { 32 return id; 33 } 34 35 public void setId(int id) { 36 this.id = id; 37 } 38 39 public String getName() { 40 return name; 41 } 42 43 public void setName(String name) { 44 this.name = name; 45 } 46 47 public String getSex() { 48 return sex; 49 } 50 51 public void setSex(String sex) { 52 this.sex = sex; 53 } 54 }
3.service返回数值类型问题
在Service下的方法里,红线标记的方法返回值类型看源码是object,但是返回值类型要求为Employees,
原因:在设置EmployeeMapper类时设置了泛型