我有这些课程:
文章类:
@Entity
@Table(name = "imei")
public class Article {
@Id
//@GeneratedValue
@Column(name = "imei1",nullable = false)
private Long imeiNo;
@Column(name = "date_added")
@Temporal(javax.persistence.TemporalType.TIMESTAMP)
private Date addedDate;
public Article() {
}
public Long getImeiNo() {
return imeiNo;
}
public void setImeiNo(Long imeiNo) {
this.imeiNo = imeiNo;
}
public Date getAddedDate() {
return addedDate;
}
public void setAddedDate(Date addedDate) {
this.addedDate = addedDate;
}
文章道类:
public interface ArticleDao {
// To Save the article detail
public void saveArticle(Article article );
// To get list of all articles
public List<Article> listArticles();
}
ArticleDaoImpl 类:
@Repository("articleDao")
public class ArticleDaoImpl implements ArticleDao {
@Autowired
private SessionFactory sessionFactory;
// To Save the article detail
public void saveArticle(Article article) {
article.setAddedDate(new Date());
sessionFactory.getCurrentSession().saveOrUpdate(article);
}
// To get list of all articles
@SuppressWarnings("unchecked")
public List<Article> listArticles() {
return (List<Article>) sessionFactory.getCurrentSession().createCriteria(Article.class).list();
}
}
文章控制器:
@Controller
@RequestMapping("/articles")
public class ArticleController {
@Autowired
private ArticleService articleService;
@RequestMapping(value = "/save", method = RequestMethod.POST)
public ModelAndView saveArticle(@ModelAttribute(" article") Article article,
BindingResult result) {
articleService.addArticle( article);
return new ModelAndView("redirect:/articles.html");
}
@RequestMapping(method = RequestMethod.GET)
public ModelAndView listArticles() {
Map<String, Object> model = new HashMap<String, Object>();
model.put("articles", articleService.listArticles());
return new ModelAndView("articlesList", model);
}
@RequestMapping(value = "/add", method = RequestMethod.GET)
public ModelAndView addArticle(@ModelAttribute("article") Article article,
BindingResult result) {
return new ModelAndView("addArticle");
}
}
文章服务:
public interface ArticleService {
public void addArticle(Article article);
public List<Article> listArticles();
}
ArticleServiceImpl 类:
@Service("articleService")
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public class ArticleServiceImpl implements ArticleService {
@Autowired
private ArticleDao articleDao;
public ArticleServiceImpl() {
}
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public void addArticle(Article article) {
articleDao.saveArticle(article);
}
public List<Article> listArticles() {
return articleDao.listArticles();
}
}
现在创建了另一个类 OnlyImei.java
@Entity
@Table(name = "onlyimei")
public class OnlyImei {
@Id
@Column(name = "imei1",nullable = false)
private Long imeiNo;
public OnlyImei() {
}
public Long getImeiNo() {
return imeiNo;
}
public void setImeiNo(Long imeiNo) {
this.imeiNo = imeiNo;
}
}
你能告诉我如何一次在两个表中输入值吗?我必须在一张表中输入imei号码,在第二张表中输入imei以及日期和时间。我已经制作了第二张表,但我不知道如何在两个表中一次输入值。