zoukankan      html  css  js  c++  java
  • SpringBoot JdbcTemplate

    引入需要的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. )通过浏览器访问即可

     

  • 相关阅读:
    20155318Java课堂实践20170510
    2017-2018-1 20155220 20155309 20155317 实验一 开发环境的熟悉
    2017-2018 20155309南皓芯 信息安全系统基础设计第五周博客
    2017-2018 20155309南皓芯 信息安全系统基础设计第四周博客
    20155309 南皓芯 信息安全系统基础设计第三周博客
    关于利用GPG加解密的实验
    20155309南皓芯第二周课堂实践
    2017-2018 20155309南皓芯 信息安全系统基础设计第一周博客
    20155309 2016-2017-2《Java程序设计》课程总结
    20155309实验五 网络编程与安全
  • 原文地址:https://www.cnblogs.com/qinzhenyu/p/12039924.html
Copyright © 2011-2022 走看看