SSM框架学习记录

SSM框架学习记录

//项目结构
SSM框架学习记录_第1张图片

流程:Controller(接受请求)——>Service(biz)(bl)(写业务函数接口)(mpl实现)——>Mapper(dao)(data)(接口)——>mapper.xml(写sql)

mpl文件夹,写函数实现
entity实体类(pojo)
Mapper:将实体映射到数据库的接口
Dao: Data Access Objects 连接数据库

logo4j2.xml(日志处理的配置文件)

controller调用service,service调用mapper;

每个mapper对应一个mapper.xml
mapper.xml文件中:我们要做到mapper namespace路径和mapper接口路径一致

@ResponseBody//自动转换成相应类型返回给前端

@RequestBody接收json数据
@RequestParam接收参数
可一起使用

mapper写接口,mapper.xml写实现,id对应函数名。


Mybatis:


<mapper namespace="写对应Mapper包的路径">
    <insert id="写对应Mapper接口的函数名" parameterType="写传入的参数类型,可省略" resultType="">
       写SQL语句,#{传入的参数名}
    insert>

<resultMap id="Teacher" type="">//返回不规则数据集,自定义
mapper>```

```xml

//yml配置文件
server:
  port: 8080

spring:
  datasource:
    username: root
    password: hfut2018214813
    #上面用户名和密码要改,下面数据库名字也要改
    url: jdbc:mysql://localhost:3306/paikaosystem?serverTimezone=CTT&characterEncoding=UTF-8&useSSL=false
    driver-class-name: com.mysql.cj.jdbc.Driver

mybatis:
  mapper-locations: classpath:mapping/*Mapper.xml
  type-aliases-package: com.example.demo.entity

#showSql
logging:
  level:
    com:
      example:
        mapper : debug

//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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0modelVersion>
    <parent>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-starter-parentartifactId>
        <version>2.3.2.RELEASEversion>
        <relativePath/> 
    parent>
    <groupId>com.examplegroupId>
    <artifactId>demoartifactId>
    <version>0.0.1-SNAPSHOTversion>
    <name>demoname>
    <description>Demo project for Spring Bootdescription>

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

    <dependencies>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-data-jdbcartifactId>
        dependency>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-jdbcartifactId>
        dependency>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-webartifactId>
        dependency>
        <dependency>
            <groupId>org.mybatis.spring.bootgroupId>
            <artifactId>mybatis-spring-boot-starterartifactId>
            <version>2.1.3version>
        dependency>

        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-devtoolsartifactId>
            <scope>runtimescope>
            <optional>trueoptional>
        dependency>
        <dependency>
            <groupId>mysqlgroupId>
            <artifactId>mysql-connector-javaartifactId>
            <scope>runtimescope>
        dependency>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-configuration-processorartifactId>
            <optional>trueoptional>
        dependency>
        <dependency>
            <groupId>org.projectlombokgroupId>
            <artifactId>lombokartifactId>
            <optional>trueoptional>
        dependency>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-testartifactId>
            <scope>testscope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintagegroupId>
                    <artifactId>junit-vintage-engineartifactId>
                exclusion>
            exclusions>
        dependency>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-testartifactId>
            <version>2.3.1.RELEASEversion>
            <scope>testscope>
        dependency>
    dependencies>

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

project>

你可能感兴趣的:(学习经验分享,spring,spring,boot,后端)