package com.example.mybatistraining1.test.service;

import com.example.mybatistraining1.test.entity.Context;
import com.example.mybatistraining1.test.entity.User;
import com.example.mybatistraining1.test.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class UserService {

    @Autowired
    private UserMapper userMapper;

    private int n=100;
    @Transactional
    public void insert() {
        User user = new User();
        user.setUsername("root");
        user.setPassword("cesgroup");
        user.setEnabled(true);
        Context build = Context.builder().username("root").password("cesgroup")
                .context("hello world:"+n).enabled(true).build();
        user.setContext(build);
        userMapper.insert(user);
        n=n-1;
        if(n>0){
            insert();
        }

    }


}
