2.SSM統合_マルチテーブル_1対1または複数対1の追加削除
1対1と複数対1の構成は同じで、ここでは一緒に置きます.
1.プロファイルは前章のように、ここではあまり書かれていません.主にMapperマッピングファイルです.
複数
インタフェース
ファイルのマッピング
エンティティークラス
1
インタフェース
ファイルのマッピング
エンティティークラス
1.プロファイルは前章のように、ここではあまり書かれていません.主にMapperマッピングファイルです.
複数
インタフェース
public interface NewsMapper {
public void addNew(News news);
public void delNew(String id);
public void updateNew(News news);
//
public List selectNew(String name);
//
public List selectAll();
// id
public News selectById(String id);
//
public List getCategoryName();
}
ファイルのマッピング
insert into t_news(content, title, author, createtime, category_id)
value(#{content},#{title},#{author},#{createtime},#{category.id})
delete from t_news where id = #{id}
update t_news
set
content = #{content},
title = #{title},
author = #{author},
createtime = #{createtime},
category_id = #{category.id}
where
id = #{id}
エンティティークラス
public class News {
private Integer id;
private String content;
private String title;
private String createtime;
private Category category;//
private String author;
// getter setter
}
1
インタフェース
public interface CategoryMapper {
public void addCategory(Category category);
public void delCategory(String id);
public void updateCategory(Category cateory);
// name
public List selectCategory(String name);
//
public List selectAll();
// id
public Category selectById(String id);
//
public List getNewsWithCate(String id);
}
ファイルのマッピング
insert into t_category(name, createtime)
value(#{name}, #{createtime});
delete from t_category
where id = #{id}
update t_category
set name = #{name}, createtime = #{createtime}
where id = #{id}
エンティティークラス
public class Category {
private Integer id;
private String name;
private String createtime;
//
private List news;
// getter setter