\"在这里插入图片描述\"

application.properties

spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/xq?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
spring.datasource.username=xq
spring.datasource.password=xq123@123
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.max-idle=10
spring.datasource.max-wait=10000
spring.datasource.min-idle=5
spring.datasource.initial-size=5

#mybatis.config-location=classpath:mybatis-config. 
#mybatis mapper文件的位置
mybatis.mapper-locations=classpath:mapper/*Mapper. 
#扫描pojo类的位置,在此处指明扫描实体类的包,在mapper中就可以不用写pojo类的全路径名了
mybatis.type-aliases-package=com.jackray.springbootshiro.mybatisutils.mapper

#logging.config=classpath:log4j2/log4j2. 

##jsp##
#spring.mvc.view.prefix=/jsp/
#spring.mvc.view.suffix=.html

pom

<?  version=\"1.0\" encoding=\"UTF-8\"?>
<project  ns=\"http://maven.apache.org/POM/4.0.0\"  ns:xsi=\"http://www.w3.org/2001/ Schema-instance\"
         xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.spring work.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.jakcray</groupId>
    <artifactId>springbootshiro</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>springbootshiro</name>
    <de ion>Demo project for Spring Boot</de ion>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.spring work.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.spring work.boot</groupId>
            <artifactId>spring-boot-starter-data-mongodb</artifactId>
        </dependency>
        <dependency>
            <groupId>org.spring work.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>
        <dependency>
            <groupId>org.spring work.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.spring work.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.spring work.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.spring work.boot</groupId>
            <artifactId>spring-boot-starter-websocket</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.3.2</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.spring work.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.alibaba/druid -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.1.12</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.spring work.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>

            <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.2</version>
                <configuration>
                    <configurationFile>${ dir}/src/main/resources/generator/generatorConfig. </configurationFile>
                    <overwrite>true</overwrite>
                    <verbose>true</verbose>
                </configuration>
            </plugin>

        </plugins>
    </build>

</project>

mapper
必须加@Repository和@Mapper注解

package com.jakcray.springbootshiro.mybatisutils.mapper;

import com.jakcray.springbootshiro.mybatisutils.dao.UserDAO;
import com.jakcray.springbootshiro.mybatisutils.dao.UserDAOExample;
import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.spring work.stereotype.Repository;


@Repository
@Mapper
public interface UserDAOMapper {
    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the data  table user
     *
     * @mbggenerated
     */
    int countByExample(UserDAOExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the data  table user
     *
     * @mbggenerated
     */
    int deleteByExample(UserDAOExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the data  table user
     *
     * @mbggenerated
     */
    int deleteByPrimaryKey(String iduser);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the data  table user
     *
     * @mbggenerated
     */
    int insert(UserDAO record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the data  table user
     *
     * @mbggenerated
     */
    int insertSelective(UserDAO record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the data  table user
     *
     * @mbggenerated
     */
    List<UserDAO> selectByExample(UserDAOExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the data  table user
     *
     * @mbggenerated
     */
    UserDAO selectByPrimaryKey(String iduser);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the data  table user
     *
     * @mbggenerated
     */
    int updateByExampleSelective(@Param(\"record\") UserDAO record, @Param(\"example\") UserDAOExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the data  table user
     *
     * @mbggenerated
     */
    int updateByExample(@Param(\"record\") UserDAO record, @Param(\"example\") UserDAOExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the data  table user
     *
     * @mbggenerated
     */
    int updateByPrimaryKeySelective(UserDAO record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the data  table user
     *
     * @mbggenerated
     */
    int updateByPrimaryKey(UserDAO record);
}

其他相关的mybatis的代码由generator 生成参照地址
idea springboot generator生成代码 8.XXX

controller

package com.jakcray.springbootshiro.controller;

import com.jakcray.springbootshiro.mybatisutils.dao.UserDAO;
import com.jakcray.springbootshiro.mybatisutils.mapper.UserDAOMapper;
import org.spring work.beans.factory.annotation.Autowired;
import org.spring work.web.bind.annotation.RequestMapping;
import org.spring work.web.bind.annotation.RequestMethod;
import org.spring work.web.bind.annotation.RestController;

@RestController
public class TestController {

    @Autowired
    UserDAOMapper userDAOMapper;

    @RequestMapping(value = \"/test\",method = RequestMethod.GET)
    public String Test(){

        UserDAO userDAO = userDAOMapper.selectByPrimaryKey(\"12345\");

        System.out.println(userDAO.getEmail());

        System.out.println(\"success\");

        return \"big success\";
    }

}

test

访问:http://localhost:8080/test

\"在这里插入图片描述\"

收藏 打印