提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
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);
}