贴一下主要的配置,做一个记录。

首先是pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-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>
  <groupId>xxx.xxx</groupId>
  <artifactId>xxx</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  
  <dependencies>
       <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.3.1</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

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


        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.1.0</version>
        </dependency>
        
        
    </dependencies>
  
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.10.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

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

</project>

yml配置:

image.png

server:
  port: 8089
  context-path: /sboot
  
spring:
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://127.0.0.1:3306/xxx
    username: root
    password: 123
  jpa:
    hibernate:
      ddl-auto: update
      show-sql: true  
  thymeleaf:
    cache: false
    
mybatis:
  typeAliasesPackage: com.app.bean
  mapperLocations: sql/*.xml

目录结构如下:

image.png

mybatis那些文件是用工具 generatorSqlmapCustom 生成的,用过的都说好。

然后记得要在mapper上面打一个mapper注解:

image.png

最后,贴上Controller的代码:

@Controller
public class IndexController {
	
	@Autowired
	private EntpriseMapper em;
	
	@RequestMapping("/")
	public String root(){
		return "redirect:/login.html";
	}
	
	@RequestMapping("/findAll")
	@ResponseBody
	public List findAll(){
		return em.selectByExample(new EntpriseExample());
	}

}