基于springboot增删改查功能


PersonController类
package com.example.qdh.study.controll;

import com.example.qdh.study.po.Person;
import com.example.qdh.study.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/person")
public class PersonController {

    //CURD
    @Autowired
    private PersonService personService;

    //person/create person/update
    @PostMapping("/create")
    public Boolean create(Person person){
        return personService.save(person);

    }
    @PostMapping("/update")
    public Boolean update(Person person){
        return personService.updateById(person);

    }
    @GetMapping("/delete")
    public Boolean delete(Integer id){
        return personService.removeById(id);
    }
    @GetMapping("/all")
    public List<Person> all(){
        return personService.list();

    }
    @GetMapping("/one")
    public Person one(Integer id){
        return personService.getById(id);
    }
}
UserinfoControll类
package com.example.qdh.study.controll;

import com.example.qdh.study.service.UserinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 *  控制层。
 *
 * @author kh_wz
 * @since 2023-11-25
 */
@RestController



public class UserinfoControll {


    @Autowired
    private final UserinfoService userinfoService;

    public UserinfoControll(UserinfoService userinfoService) {
        this.userinfoService = userinfoService;
    }

    @RequestMapping("/login")
    public long login(String userName,String password) {

        return userinfoService.login(userName,password);
    }



        
        



}
PersonMapper接口
package com.example.qdh.study.Mapper;

import com.example.qdh.study.po.Person;
import com.mybatisflex.core.BaseMapper;

public interface PersonMapper extends BaseMapper<Person> {
}
UserinfoMapper类
package com.example.qdh.study.Mapper;

import com.example.qdh.study.po.Userinfo;
import com.mybatisflex.core.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface UserinfoMapper extends BaseMapper<Userinfo> {
    @Select("SELECT * FROM userinfo WHERE id=#{id} ")
    Userinfo selectById(@Param("id") int id);

    @Select("SELECT * FROM userinfo WHERE user_name=#{name} and password=#{pwd}")
    Userinfo login(@Param("name") String name ,@Param("pwd") String pwd);


    Userinfo selectByName(@Param("name") String name);


    List<Userinfo> selectPage(@Param("pageOffset") int pageOffset, @Param("pageSize") int pageSize);

}
Person类
package com.example.qdh.study.po;

import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.annotation.Table;
import lombok.Data;

import java.sql.Date;

@Data
@Table("tb_person")
public class Person {
    @Id(keyType = KeyType.Auto)
    private Integer id;

    private String name;

    @Column(isLarge = true)
    private String description;

    @Column(onInsertValue = "now()")
    private Date createTime;

    @Column(onInsertValue = "now()",onUpdateValue = "now()")
    private Date updateTime;

    @Column(isLogicDelete = true)
    private Boolean isDeleted;
}
Userinfo类
package com.example.qdh.study.po;

import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.annotation.Table;
import lombok.Data;

@Data
@Table("userinfo")
public class Userinfo {
    @Id(keyType = KeyType.Auto)
    private int id;
    private String user_name,password;
}
PersonServiceImpl类
package com.example.qdh.study.service.impl;

import com.example.qdh.study.Mapper.PersonMapper;
import com.example.qdh.study.po.Person;
import com.example.qdh.study.service.PersonService;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

@Service
public class PersonServiceImpl extends ServiceImpl<PersonMapper, Person> implements PersonService {
}
UserinfoServiceImpl类
package com.example.qdh.study.service.impl;

import com.example.qdh.study.Mapper.UserinfoMapper;
import com.example.qdh.study.po.Userinfo;
import com.example.qdh.study.service.UserinfoService;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserinfoServiceImpl extends ServiceImpl<UserinfoMapper , Userinfo> implements UserinfoService {
    @Autowired
    private UserinfoMapper userinfoMapper;
    @Override
    public Integer login(String userName, String password) {
        Userinfo u=userinfoMapper.login(userName,password);
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("user_name",userName);
        queryWrapper.eq("password",password);
        int a= (int) userinfoMapper.selectCountByQuery(queryWrapper);
        return a;
    }
}

 UserinfoService接口

package com.example.qdh.study.service;

import com.example.qdh.study.po.Userinfo;
import com.mybatisflex.core.service.IService;

public interface UserinfoService extends IService<Userinfo> {
    Integer login(String userName,String password);
}

PersonService接口 

package com.example.qdh.study.service;

import com.example.qdh.study.po.Person;
import com.mybatisflex.core.service.IService;

public interface PersonService extends IService<Person> {
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值