springboot+mybatis+sql service实现简单的增删改查操作(注解开发,前后端分离)

本文记录了一个使用SpringBoot、Mybatis和SQL Service进行注解开发的小项目,实现了前后端分离的增删改查功能。在Controller层,通过参数注入实现与前端的交互,当参数较多时,可创建实体类封装参数。DAO层利用注解配合mapper.xml文件进行数据操作,Service层则完成业务逻辑。整个过程简化了参数绑定,提高了开发效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近接手一个springboot+mybatis+sql service的一个小项目:在这里记录一下自己的 简单实现操作:

coltroller层:

package springBootOltPriject.olt.coltroller;


import java.util.List;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import springBootOltPriject.olt.service.OltService;
import springBootOltPriject.olt.vo.SpringBootOtl;





@MapperScan("springBootOltPriject.olt.dao")
//@Controller是这个注解可以return 页面
@RestController
@SpringBootApplication
@ComponentScan("springBootOltPriject.olt.service")
//@RequestMapping("/")
public class CotrollerDemo {
	//注入OltService
	@Autowired
	private OltService oltService;
	
	
	
//根据id查询数据   ===================================================================
	//@GetMapping("/upolt")
	/**
	 * 
	 * @param id
	 * @return
	 */
	
	@RequestMapping(value ="/upolt")
	public SpringBootOtl   getOltMappingById( int  id) {
		System.out.println(id);
		SpringBootOtl springBootOtl=	oltService.getOltMappingById(id);
		return springBootOtl;
	}
							
						////查询所有数据
						//	
						//	@RequestMapping("/oltEdit")
						//	public ModelAndView  getAll(){
						//		
						//		ModelAndView view = new ModelAndView("oltEdit");
						//		//查询数据
						//		List<SpringBootOtl> list=oltService.getAll();
						//		view.addObject("list", list);
						//		return view;
						//	}
	
	

//查询所有数据 完成===================================================================
	
	@RequestMapping("/getAll")
	public List<SpringBootOtl>  getAll(){
		//查询数据
		List<SpringBootOtl> list=oltService.getAll();
		//测试
		System.out.println(list.get(0));
		return list;
	}
	
//根据id删除数据  完成 ==============================================================
	
	//@GetMapping("/delById")
	@RequestMapping(value="/delById")
	public int   delById( int  id){
		//从数据库删除数据
		oltService.delById(id);
		
		return 1;
	}
	
//根据id跟新数据  =============================================
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值