
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> {
}

被折叠的 条评论
为什么被折叠?



