1. 程式人生 > >SSH框架之Hibernate資料庫外來鍵如何插入值的問題

SSH框架之Hibernate資料庫外來鍵如何插入值的問題

package com.teacher.web.action;
import java.util.Date;
import com.pojos.Course_information;
import com.pojos.Teacher_information;
import com.teacher.comm.BaseAction;
import com.teacher.service.CourseService;
import com.teacher.service.Teacher_informationService;


@SuppressWarnings("serial")
public class CourseManagerAction extends BaseAction{
/*定義所有屬性*/
private Integer Course_id;
private String Course_name;
private Integer Course_level;
private String Course_sign_begin;
private String Course_sign_end;
private Date Course_add_time;
private Integer Course_option_numer;
private String Course_message;

/*定義教師表物件  記錄當前教師的工號和教師編號*/
private Integer Tea_id;
private String Tea_number;

private Course_information course_information;

/*定義服務層  介面類物件*/
private Teacher_informationService teacher_informationService;

private CourseService courseService;

/*進入新增課程頁面*/
public String add_course(){
System.out.println("當前的教師工號:"+Tea_number);
return "add_course";
}
public String save_new_course(){
try{
Course_information course = new Course_information();
course.setCourse_name(Course_name);
System.out.println("當前的教師工號:"+Tea_number);
Teacher_information tea = teacher_informationService.findBy_Tea_number(Tea_number);
System.out.println("獲取到的當前教師編號為:"+tea.getTea_id());
course.setTeacher_information(tea);
course.setCourse_level(Course_level);
course.setCourse_sign_begin(Course_sign_begin);
course.setCourse_sign_end(Course_sign_end);
course.setCourse_add_time(new Date());
course.setCourse_message(Course_message);
courseService.saveOneCourse(course);
}catch(Exception e){
System.out.println(e.toString());
}
return "add_course_ok";
}

public Integer getCourse_id() {
return Course_id;
}
public void setCourse_id(Integer courseId) {
Course_id = courseId;
}
public String getCourse_name() {
return Course_name;
}
public void setCourse_name(String courseName) {
Course_name = courseName;
}
public Integer getCourse_level() {
return Course_level;
}
public void setCourse_level(Integer courseLevel) {
Course_level = courseLevel;
}

public Date getCourse_add_time() {
return Course_add_time;
}
public void setCourse_add_time(Date courseAddTime) {
Course_add_time = courseAddTime;
}
public String getCourse_message() {
return Course_message;
}
public void setCourse_message(String courseMessage) {
Course_message = courseMessage;
}
public CourseService getCourseService() {
return courseService;
}
public void setCourseService(CourseService courseService) {
this.courseService = courseService;
}
public Integer getTea_id() {
return Tea_id;
}


public void setTea_id(Integer teaId) {
Tea_id = teaId;
}


public String getTea_number() {
return Tea_number;
}


public void setTea_number(String teaNumber) {
Tea_number = teaNumber;
}


public Teacher_informationService getTeacher_informationService() {
return teacher_informationService;
}


public void setTeacher_informationService(
Teacher_informationService teacherInformationService) {
teacher_informationService = teacherInformationService;
}
public String getCourse_sign_begin() {
return Course_sign_begin;
}
public void setCourse_sign_begin(String courseSignBegin) {
Course_sign_begin = courseSignBegin;
}
public String getCourse_sign_end() {
return Course_sign_end;
}
public void setCourse_sign_end(String courseSignEnd) {
Course_sign_end = courseSignEnd;
}
public Integer getCourse_option_numer() {
return Course_option_numer;
}
public void setCourse_option_numer(Integer courseOptionNumer) {
Course_option_numer = courseOptionNumer;
}
public Course_information getCourse_information() {
return course_information;
}
public void setCourse_information(Course_information courseInformation) {
course_information = courseInformation;
}
}