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> 

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);

}

上一篇:翻煎饼 Stacks of Flapjacks


下一篇:hihoCoder #1445 : 后缀自动机二·重复旋律5