mysql插入数据自动生成主键uuid
DemoMapper.java
//注意方法的返回值必须是void;
void add(Demo demo);
==============================================
demoMapper.xml:
<insert id="add" parameterType="com.demo.pojo.Demo">
<selectKey keyProperty="demoId" resultType="java.lang.String" order="BEFORE">
select replace(uuid(),'-','')
</slectKey>
select replace(uuid(),'-','')
</slectKey>
INSERT INTO
db_demo(
demo_id
,name
,age
)
VALUES
(
#{demoId}
,#{name}
,#{age}
)
</insert>
==============================================
DemoServiceImpl.java :
@Autowired
private demoMapper demoMapper;
public void add(Demo demo){
demoMapper.add(demo);
System.out.println(demo.getDemoId);
}
梅花香自古寒来