Spring boot增删改查

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档

Java增删改查

controller类

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
/*@RequestMapping("/order")*/
public class OrderController {
    @Autowired
    private OrederService orederService;

    //查询数据
    @RequestMapping("/find")
    public List<Order> find() {
        return orederService.find();
    }

    //*新增数据*//*
    @RequestMapping("/ad")
    public void addOrder(@RequestParam("PatName") String PatName) {
        System.out.println(PatName);
        orederService.addOrder(PatName);
    }

    //*删除数据*//*
    @RequestMapping("/delta")
    public void deleteOrder(@RequestParam("PatName") String PatName) {
        orederService.deleteOrder(PatName);
        System.out.println(PatName);
    }

    //*修改数据*//
    @PostMapping("/updata")
    public void updateOrder(Order order) {
        orederService.updateOrder(order);
    }
}

Dao接口

package com.example.demo.dao;

import com.example.demo.bean.Order;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface Dao {
    /*查询*/
    @Select("select * from preson")
    List<Order> find();

    //新增数据
    @Insert("insert into preson (PatName)values(#{PatName})")
    void addOrder(String PatName);


    //删除数据
    @Delete("delete from preson where PatName=#{PatName}")
    void deleteOrder(String PatName);

    //修改数据
    @Update("update preson set PatName=#{PatName}")
    void updateOrder(Order order);

}

service类

package com.example.demo.sevice.impl;

import com.example.demo.bean.Order;

import com.example.demo.dao.Dao;
import com.example.demo.sevice.OrederService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServiceImpl implements OrederService {
    @Autowired
    private Dao dao;

    /*查询数据 */
    @Override
    public List<Order> find() {
        return dao.find();
    }

    /*新增数据*/
    @Override
    public void addOrder(String PatName) {
       dao.addOrder(PatName);
    }

    /*删除数据*/
    @Override
    public void deleteOrder(String  PatName) {
         dao.deleteOrder(PatName);
    }

    /*修改数据*/
    @Override
    public void updateOrder(Order order) {
         dao.updateOrder(order);
    }
}
package com.example.demo.sevice;

import com.example.demo.bean.Medical;
import com.example.demo.bean.Order;

import java.util.List;

public interface OrederService {
    //查询
    List<Order> find();

    //新增
    void addOrder(String  PatName);

    //删除
    void deleteOrder(String  PatName);

    //修改
   void updateOrder(Order order);
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值