这是后端Controller代码
package com.example.demo.controller;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo.controller.dto.cuserDTO;
import com.example.demo.entity.cuser;
import com.example.demo.mapper.cusermapper;
import com.example.demo.service.cuserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.web.WebProperties;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.swing.text.AbstractDocument;
import java.sql.Struct;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/user")
public class UserController {
@Resource
private cusermapper cusermapper;
@PostMapping
public boolean login(@RequestBody cuserDTO cuserDTO)
{System.out.println(cuserDTO.getCname());
String username=cuserDTO.getCname();
String password=cuserDTO.getCpassword();
if(StrUtil.isBlank(username)||StrUtil.isBlank(password))
{ System.out.println(username);
return false;
}else {
List<cuser> data= cusermapper.login(cuserDTO);
if (data==null){return false;}
else {return true; }
}}
@GetMapping("/all")
public List<cuser> index(){
return cusermapper.findAll();
}
}
这是前端的数据和方法:
<script>
import HelloWorld from '@/components/HelloWorld.vue'
import request from "@/utils/request"
export default {
name: "login",
data(){
return{
cuserDTO:{}
}
},
methods:{
shiyan(){
this.$router.push("/Home")
},
login(){
let config = {
headers: {
"Content-Type": "application/json"
},
};
request.post("/user",JSON.stringify(this.cuserDTO),config).then(res => {
if(!res){
console.log(res)
console.log(this.cuserDTO)
this.$message.error("登录失败")
}else{
console.log(this.cuserDTO)
this.$router.push("/Home")
}})
}
}
}
</script>