SpringBoot-Vue实现增删改查

pojo层·

package com.example.pojo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class User {
    private int id;
    private String name;
    private String pwd;
}

mapper层 

package com.example.mapper;

import com.example.pojo.User;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Param;

import java.util.List;

public interface UserMapper {
    /**
     * 查
     * @return
     */
    ListqueryUser();

    /**
     * 增
     * @param user
     * @return
     */
    int addUser(User user);


    /**
     * 修改
     * @param user
     * @return
     */
    int updateUser(User user);

    /**
     * 删除
     * @param id
     * @return
     */
    int deleteUser(@Param("id") int id);


}

mapper.xml 





    

    
        insert into user(id,name,pwd) values (null,#{name},#{pwd})
    

    
        update user set name=#{name},pwd=#{pwd} where id=#{id}
    

    
        delete from user where id=#{id}
    


service层

package com.example.servict;

import com.example.pojo.User;
import org.apache.ibatis.annotations.Param;

import java.util.List;

public interface UserService {
    /**
     * 查
     * @return
     */
    ListqueryUser();

    /**
     * 增
     * @param user
     * @return
     */
    int addUser(User user);

    /**
     *根据id查询
     * @param id
     * @return
     */
    User queryById(@Param("id") int id);

    /**
     * 修改
     * @param user
     * @return
     */
    int updateUser(User user);

    /**
     * 删除
     * @param id
     * @return
     */
    int deleteUser(@Param("id") int id);

 
}

serviceImpl层 

 

package com.example.servict;

import com.example.mapper.UserMapper;
import com.example.pojo.User;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl implements UserService{
    @Resource
    private UserMapper userMapper;

    @Override
    public List queryUser() {
        return userMapper.queryUser();
    }

    @Override
    public int addUser(User user) {
        return userMapper.addUser(user);
    
    }

    @Override
    public int updateUser(User user) {
        return userMapper.updateUser(user);
    }

    @Override
    public int deleteUser(int id) {
        return userMapper.deleteUser(id);
    }

}

controller层

package com.example.controller;


import com.example.mapper.UserMapper;
import com.example.pojo.JsonPojo;
import com.example.pojo.User;
import com.example.servict.UserServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.boot.system.ApplicationHome;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.util.List;


@Controller
@RequestMapping("/a")
public class MyController {
    @Resource
    private UserServiceImpl userService;

    @RequestMapping("/index")
    public String test(){
        return "index";
    }
    @RequestMapping("/queryUser")
    @ResponseBody
    public JsonPojo queryUser(){
        JsonPojo>jsonPojo=new JsonPojo<>();
        List list = userService.queryUser();
        jsonPojo.setStatu(200);
        jsonPojo.setMsg("成功");
        jsonPojo.setData(list);
        return jsonPojo;
    }
    @RequestMapping("/updateUser")
    @ResponseBody
    public JsonPojo updateUser(User user){
        JsonPojojsonPojo=new JsonPojo<>();
        jsonPojo.setStatu(200);
        jsonPojo.setMsg("修改成功");
        jsonPojo.setData(userService.updateUser(user));
        return jsonPojo;
    }

    @RequestMapping("/addUser")
    @ResponseBody
    public JsonPojo addUser(User user){
        JsonPojojsonPojo=new JsonPojo<>();
        jsonPojo.setStatu(200);
        jsonPojo.setMsg("新增成功");
        jsonPojo.setData(userService.addUser(user));
        return jsonPojo;
    }

    @RequestMapping("/deleteUser")
    @ResponseBody
    public JsonPojo deleteUser(int id){
        JsonPojojsonPojo=new JsonPojo<>();
        jsonPojo.setStatu(200);
        jsonPojo.setMsg("删除成功");
        jsonPojo.setData(userService.deleteUser(id));
        return jsonPojo;
    }

}

前端




    
    Title
    
    
    
    
    


id 姓名 年龄 操作
{{user.id}} {{user.name}} {{user.pwd}} 修改 删除

姓名:
密码:

姓名:
密码:

你可能感兴趣的:(vue.js,spring,boot,java)