get/set方法传值赋值与直接传值赋值的区别
service层中的某个函数:
public class ManangeMananger extends ServiceException {
public String TIME;
public void CreateTable() throws Exception{
Date now = new Date();
DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
this.setTIME(dateFormat.format(now));
//this.TIME = dateFormat.format(now);
System.out.println(TIME);
String sql = "CREATE TABLE backup_docinfo_"
+ this.TIME
+ "各个字段";
ConnectionDB ed = new ConnectionDB();
try {
ed.ExcuteSql(sql);
} catch (Exception e) {
e.printStackTrace();
}
}
public String getTIME() {
return TIME;
}
public void setTIME(String tIME) {
TIME = tIME;
}
}
在web层某个函数调用了CreateTable()方法中的TIME变量。
private String backuptime;
private ManangeMananger manangeManager;
public void InsertData() throws Exception{
//this.backuptime = this.manangeManager.TIME;
this.backuptime = this.manangeManager.getTIME();
……;
……;
}
public String getBackuptime() {
return backuptime;
}
public void setBackuptime(String backuptime) {
this.backuptime = backuptime;
}
@Autowired
public void setManangeManager(ManangeMananger manangeManager) {
this.manangeManager = manangeManager;
}
我想问的是如果不使用get/set方法传值赋值,而是直接写this.TIME = dateFormat.format(now);这时候TIME有值,但是传过去给backuptime显示的就是null了。这是为什么。直接传值赋值与用get/set传值赋值有什么区别吗?请指教~~