最近接手一个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跟新数据 =============================================