我有很多用户->属性关系:
CREATE TABLE user (
id INT IDENTITY (1, 1),
name VARCHAR (100) NOT NULL,
surname VARCHAR (100) NOT NULL,
phone VARCHAR (100) NOT NULL,
mail VARCHAR (100) NOT NULL,
created DATE NOT NULL,
CONSTRAINT PK_user PRIMARY KEY (id)
)
CREATE TABLE properties (
id INT IDENTITY (1, 1),
name VARCHAR (100) NOT NULL,
value VARCHAR (100) NOT NULL,
created DATE NOT NULL,
CONSTRAINT PK_properties PRIMARY KEY (id)
)
CREATE TABLE user_properties (
user_id INT NOT NULL,
property_id INT NOT NULL,
CONSTRAINT PK_user_properties PRIMARY KEY (user_id, property_id),
CONSTRAINT FK_user_properties_users FOREIGN KEY (user_id) REFERENCES users (id),
CONSTRAINT FK_user_properties_properties FOREIGN KEY (property_id) REFERENCES properties (id)
)
如何在同一句话中插入具有各自属性的用户列表。我的xml文件中有以下配置:
<insert id='insertUsers' parameterType='users'>
INSERT INTO users
(name, surname, phone, mail, created)
VALUES
<foreach item="item" collection="list" separator=",">
(#{item.name}, #{item.surname}, #{phone.value}, #{phone.mail}, GETDATE())
</foreach>
</insert>
我可以检索userid并在保存用户的循环中链接另一个forech循环吗?
暂无答案!
目前还没有任何答案,快来回答吧!