引入需要的pom文件节点
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
(1. )创建GradeDao类
package com.qzy.dao;
import com.qzy.entity.Grade;
import java.util.List;
public interface IGradeDao {
public int insertGrade(Grade grade);
public int updateGrade(Grade grade);
public int deleteGrade(Integer id);
public List<Grade> findAll();
}
(2. )创建IGradeService类
package com.qzy.service.impl;
import com.qzy.dao.IGradeDao;
import com.qzy.entity.Grade;
import com.qzy.service.IGradeService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service("iGradeService")
public class IGradeServiceImpl implements IGradeService {
@Resource
private IGradeDao iGradeDao;
@Override
public int insertGrade(Grade grade) {
return iGradeDao.insertGrade(grade);
}
@Override
public int updateGrade(Grade grade) {
return iGradeDao.updateGrade(grade);
}
@Override
public int deleteGrade(Integer id) {
return iGradeDao.deleteGrade(id);
}
@Override
public List<Grade> findAll() {
return iGradeDao.findAll();
}
}
(3. )创建JDBCTemplateController类
package com.qzy.controller;
import com.qzy.entity.Grade;
import com.qzy.service.IGradeService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
@RestController
public class JDBCTemplateController {
@Resource
private IGradeService iGradeService;
@RequestMapping("/insertGrade")
public int insertGrade(){
return iGradeService.insertGrade(new Grade("S10"));
}
@RequestMapping("/updateGrade")
public int updateGrade(){
return iGradeService.updateGrade(new Grade(10012,"S1"));
}
@RequestMapping("/deleteGrade")
public int deleteGrade(){
return iGradeService.deleteGrade(8);
}
@RequestMapping("/findAll")
public List<Grade> findAll(){
return iGradeService.findAll();
}
}
(4. )通过浏览器访问即可