私はこれらのクラスを持っています:
記事クラス:
@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;
}
ArticleDao クラス:
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();
}
}
ArticleController:
@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;
}
}
一度に 2 つのテーブルに値を入力する方法を教えてください。1 つのテーブルに imei 番号を入力し、2 番目のテーブルに imi と日時を入力する必要があります。2 つ目のテーブルを作成しましたが、2 つのテーブルに同時に値を入力する方法がわかりません。