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. )通过浏览器访问即可

     

  • 相关阅读:
    C#综合揭秘——Entity Framework 并发处理详解
    Apache2.2+Tomcat7.0整合配置详解
    python操作excel
    NameError: name ‘time‘ is not defined
    ping命令最实用的
    github使用方法
    数字证书
    网络编程
    不辣的皮特
    msdn上的“索引器”(indexer)示例
  • 原文地址:https://www.cnblogs.com/qinzhenyu/p/12039924.html
Copyright © 2011-2022 走看看