新建
控制器,controllor
持久层 dao
服务层 service

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class) spring  boot不默认加载数据库

配制

在resource 文件夹下面,配制,application.yml 文件 配制端口号,前置文件名,datasource,mybatis 等,信息

server:
  port: 1234
spring:
  mvc:
    view:
      prefix:
      suffix: html
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://localhost:3306/java?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true
    password: root
    username: root
mybatis:
  mapper-locations: classpath:/mapper/*.xml

如果需要返回页面需要配制pop.xml  的 thymeleaf 模板

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
@MapperScan("com.example.demo.dao") 可以扫描mapper类包的路径,添加在,启动类上面

在 resource 下面 添加 mapper 文件夹 并新建,mapper.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.demo.dao.UserDao">
    <select id="userDanyi" resultType="Map" parameterType="string">
        select * from user where name = #{name}
    </select>
</mapper>

 

 

 

 

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐