MyBatisPlusMapper.kt 717 字节
Newer Older
2
2293736867 已提交
1 2 3 4 5 6 7 8 9
package com.example.demo.service

import com.example.demo.dao.UserMapper
import com.example.demo.entity.User
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component
import org.springframework.stereotype.Service

@Service
10
class MyBatisPlusMapper {
2
2293736867 已提交
11 12 13
    @Autowired
    private lateinit var mapper: UserMapper

14 15
    fun save(user: User): Boolean {
        if (mapper.selectById(user.id) != null)
2
2293736867 已提交
16 17 18 19
            return mapper.updateById(user) == 1
        return mapper.insert(user) == 1
    }

20
    fun delete(id: String) = (mapper.deleteById(id) == 1)
2
2293736867 已提交
21

22
    fun select(id: String): User? = mapper.selectById(id)
2
2293736867 已提交
23

24
    fun selectAll(): List<User> = mapper.selectList(null)
2
2293736867 已提交
25
}