zoukankan      html  css  js  c++  java
  • springboot+mybatis结合使用

    springboot+mybatis结合使用与普通的ssm配置差别不大,但是少了很多的配置,如spring.xml  web.xml,  给程序员减轻了很多负担

    首先创建带有mybatis框架的项目

    *.xml配置与ssm无异

    配置application.properties

    spring.datasource.driver-class-name=com.mysql.jdbc.Driver
    spring.datasource.url=jdbc:mysql://localhost:3306/m1
    spring.datasource.username=root
    spring.datasource.password=mlh123456
    mybatis.type-aliases-package=com.test.entity
    mybatis.mapper-locations=classpath:mapper/*.xml

    entity层

    package com.test.entity;
    
    /**
     * Created by MY on 2017/8/15.
     */
    public class Girls {
        private Integer id;
        private String cup_size;
        private Integer age;
    
        public Girls(Integer id, String cup_Size, Integer age) {
            this.id = id;
            this.cup_size = cup_size;
            this.age = age;
        }
    
        public String getCup_size() {
            return cup_size;
        }
    
        public void setCup_size(String cup_Size) {
            this.cup_size = cup_Size;
        }
    
        public Integer getId() {
            return id;
        }
    
        public void setId(Integer id) {
            this.id = id;
        }
    
    
    
        public Integer getAge() {
            return age;
        }
    
        public void setAge(Integer age) {
            this.age = age;
        }
    
        public Girls() {
    
        }
    }

    dao层 **类名注解**  @Mapper该注解只表示与*.xml的映射,不能表示将该对象交给spring管理

    package com.test.dao;
    
    import com.test.entity.Girls;
    import org.apache.ibatis.annotations.Mapper;
    import org.springframework.stereotype.Repository;
    
    import java.util.List;
    
    /**
     * Created by MY on 2017/8/15.
     */
    @Mapper
    @Repository
    public interface GirlsDao {
        List<Girls> findAllGirls();
    }

    controller层

    package com.test.contoller;
    
    import com.test.dao.GirlsDao;
    import com.test.entity.Girls;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.ResponseBody;
    
    import java.util.List;
    
    /**
     * Created by MY on 2017/8/15.
     */
    @Controller
    public class FirstController {
    
        @Autowired
        private GirlsDao gd;
    
        @RequestMapping("first")
        public String first(){
            return "abc";
        }
    
        @ResponseBody
        @RequestMapping("find.do")
        public List<Girls> findAllGirls(){
            return gd.findAllGirls();
        }
    
    }
  • 相关阅读:
    深入浅出AQS之组件概览
    深入浅出AQS之条件队列
    深入浅出AQS之共享锁模式
    深入浅出AQS之独占锁模式
    Android中RecyclerView用法,一步一步教你如何使用RecyclerView以及带你走过编码中可能会出现的坑~
    检测jquery是否正确引入
    对于使用JDBC连接mysql数据时The server time zone value '¤¤°ê¼Ð·Ç®É¶¡'...的异常问题解决。
    MYSQL8.0以上版本ROOT密码报错及修改
    MYSQL安装教程
    linux centos安装nginx1.7.4
  • 原文地址:https://www.cnblogs.com/rzqz/p/7365470.html
Copyright © 2011-2022 走看看