return db.page("""
select * from tb_user
<where>
<if test="username != null and username != ''">
and username like concat('%',#{username},'%')
</if>
</where>
""")
magic-api中发起请求
请求结果
新增
magic-api中代码
import 'com.example.utils.Md5Util' as Md5Utilvar username = body.username
var password =Md5Util.genMd5(body.password)var count = db.selectInt("select count(*) from tb_user where username = #{username}")if(count >0){
exit "400","用户名已存在!"}var sql ="""
insert into tb_user(username,password,CreateTime) values(#{username},#{password},now())
"""
db.insert(sql)
magic-api中请求
修改
magic-api中代码
var sql ="""
update tb_user
set username = #{body.username}
where id = #{body.id}
"""return db.update(sql)
magic-api中请求
删除
magic-api中代码
import 'com.example.utils.JwtUtil' as JwtUtilvar userId =JwtUtil.getUserId()if(userId == id){
exit 400,"不能删除当前登录用户";}var sql ="""
delete from tb_user where id = #{id}
"""
db.update(sql)
magic-api中请求
批量删除
magic-api中代码
import 'com.example.utils.JwtUtil' as JwtUtilvar userId =JwtUtil.getUserId()if(ids.contains(String.valueOf(userId))){
exit 400,"不能删除当前登录用户";}var sql ="""
delete from tb_user where id in (${ids})
"""
db.update(sql)