Spring Boot xml映射

Spring Boot xml映射

实体层

@Data 里面包含get()与set()以级toString方法等等,可以大大提高写代码的效率
@TableName 是指向那个数据表

package com.zhdj.pojo;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.time.LocalDateTime;

@Data
//@Getter
//@Setter
@Accessors(chain = true)
@TableName("t_learning")
public class Learning  implements Serializable {
    private static final long serialVersionUID = 1L;
    @TableId(value = "id",type = IdType.AUTO)
    private Long id;
    @TableField("title")
    private  String title;
    @TableField("chapter")
    private  String chapter;
    @TableField("directory")
    private  String directory;
    @TableField("cover")
    private  String cover;
    @TableField("type")
    private  String type;
    @TableField("vide")
    private  String vide;
    @TableField("like_num")
    private  int likeNum;
    @TableField("watch")
    private  int watch;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "Asia/Shanghai")
    @TableField("time")
    private LocalDateTime time;
}

}

持久层

package com.zhdj.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zhdj.pojo.Learning;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

@Mapper
public interface LearningMapper extends BaseMapper<Learning> {
   
}

xml映射

column对映的是数据库数据名称,property对映的是实体类取的名称

<?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.zhdj.dao.LearningMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.zhdj.pojo.Learning">
        <id column="id" property="id"/>
        <result column="title" property="title"/>
        <result column="chapter" property="chapter"/>
        <result column="directory" property="directory"/>
        <result column="cover" property="cover"/>
        <result column="type" property="type"/>
        <result column="vide" property="vide"/>
        <result column="like_num" property="likeNum"/>
        <result column="watch" property="watch"/>
        <result column="time" property="time"/>
    </resultMap>
   <select id="findAllType" resultType="com.zhdj.pojo.Learning">
        SELECT * from t_learning
    </select>
   
</mapper>
package com.zhdj.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zhdj.pojo.Learning;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

@Mapper
public interface LearningMapper extends BaseMapper<Learning> {
   List<Learning> findAllType();
}

工具类

前端响应状态码就是这工具类生成的,例如成功状态码200、失败状态码500

package com.zhdj.utilts;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 公共返回对象
 *
 * @author wj
 * @since 1.0.0
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class RespUtil {
    private long code;
    private String message;
    private Object obj;

    public RespUtil(long code, String message) {
        this.code=code;
        this.message=message;
    }


    /**
     * 返回成功的信息
     * @param message
     * @return
     */
    public static RespUtil success(String message){
        return new RespUtil(200,message,null);
    }

    /**
     * 返回成功信息且带数据
     * @param message
     * @param obj
     * @return
     */
    public static RespUtil success(String message, Object obj){
        return new RespUtil(200,message,obj);
    }
    public static RespUtil success( Object obj){
        return new RespUtil(200,"查询成功!!!",obj);
    }

    /**
     * 返回失败信息
     * @param message
     * @return
     */
    public static RespUtil error(String message){
        return new RespUtil(500,message,null);
    }

    /**
     * 返回失败信息并带数据
     * @param message
     * @param obj
     * @return
     */
    public static RespUtil error(String message, Object obj){
        return new RespUtil(500,message,obj);
    }
    public static RespUtil error(){
        return new RespUtil(500,"查询失败!!!");
    }
    public static RespUtil errorTime(String message, Object obj){
        return new RespUtil(304,message,obj);
    }
    public static RespUtil errorTime(String message){
        return new RespUtil(304,message,null);
    }

}

业务层

service 接口

package com.zhdj.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.zhdj.pojo.Learning;
import com.zhdj.utilts.RespUtil;

import java.util.List;

public interface ILearningService extends IService<Learning> {
    RespUtil findAllType();
   
}

serviceIpmI

package com.zhdj.service.serviceIpmI;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhdj.dao.LearningMapper;
import com.zhdj.dao.SwiperMapper;
import com.zhdj.pojo.Learning;
import com.zhdj.pojo.Swiper;
import com.zhdj.service.ILearningService;
import com.zhdj.service.ISwiperService;
import com.zhdj.utilts.RespUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class ILearningServiceIpmI extends ServiceImpl<LearningMapper, Learning> implements ILearningService {
    @Resource LearningMapper learningMapper;
    @Override
    public RespUtil findAllType() {
        if (learningMapper.findAllType().size()!=0)
            return  RespUtil.success(learningMapper.findAllType());
        return  RespUtil.error();
    }
}

控制层

package com.zhdj.controller;

import com.alibaba.fastjson.JSONObject;
import com.zhdj.pojo.Learning;
import com.zhdj.service.ILearningService;
import com.zhdj.utilts.RespUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/learning")
public class LearningController {
    @Resource
    ILearningService iLearningService;
    @GetMapping("/findAllType")
    public RespUtil findAllType(){
        return  iLearningService.findAllType();
    }
   
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
spring boot中文文档,从安装到部署。 I. Spring Boot文件 1.关于文档 2.获得帮助 3.第一步 4.使用Spring Boot 5.了解Spring Boot功能 6.转向生产 7.高级主题 II。入门 8.介绍Spring Boot 9.系统要求 9.1.Servlet容器 10.安装Spring Boot 10.1.Java Developer的安装说明 10.1.1.Maven安装 10.1.2.Gradle安装 10.2.安装Spring Boot CLI 10.2.1.手动安装 10.2.2.使用SDKMAN安装! 10.2.3.OSX Homebrew安装 10.2.4.MacPorts安装 10.2.5.命令行完成 10.2.6.Windows Scoop安装 10.2.7.快速启动Spring CLI示例 10.3.从早期版本的Spring Boot升级 11.开发您的第一个Spring Boot应用程序 11.1.创建POM 11.2.添加Classpath依赖项 11.3.编写代码 11.3.1.@RestController和@RequestMapping Annotations 11.3.2.@EnableAutoConfiguration注释 11.3.3.“主要”方法 11.4.运行示例 11.5.创建一个可执行的Jar 12.接下来要阅读的内容 III。使用Spring Boot 13.构建系统 13.1.依赖管理 13.2.Maven 13.2.1.继承Starter Parent 13.2.2.在没有父POM的情况下使用Spring Boot 13.2.3.使用Spring Boot Maven插件 13.3.Gradle 13.4.Ant 13.5.Starters 14.构建您的代码 14.1.使用“默认”包 14.2.找到主应用程序类 15.配置类 15.1.导入其他配置类 15.2.导入XML配置 16.自动配置 16.1.逐步更换自动配置 16.2.禁用特定的自动配置类 17. Spring Beans和依赖注入 18.使用@SpringBootApplication Annotation 19.运行您的应用程序 19.1.从IDE运行 19.2.作为打包应用程序运行 19.3.使用Maven插件 19.4.使用Gradle插件 19.5.热插拔 20.开发人员工具 20.1.Property默认值 20.2.自动重启 20.2.1.记录条件评估中的更改 20.2.2.不包括资源 20.2.3.观看其他路径 20.2.4.禁用重启 20.2.5.使用触发器文件 20.2.6.自定义重新启动类加载器 20.2.7.已知限制 20.3.LiveReload 20.4.全局设置 20.5.远程应用 20.5.1.运行远程客户端应用程序 20.5.2.远程更新 21.包装您的生产
1.1 前言 1.2 资料官网 1.3 spring boot起步之Hello World 1.4 Spring Boot返回json数据 1.5 Spring Boot热部署 1.6 Spring Boot使用别的json解析框架 1.7 全局异常捕捉 1.8 Spring Boot datasource - mysql 1.9 JPA - Hibernate 1.10 使用JPA保存数据 1.11 使用JdbcTemplate 1.12 Spring Boot修改端口号 1.13 Spring Boot配置ContextPath 1.14 Spring Boot改变JDK编译版本 1.15 处理静态资源(默认资源映射) 1.16 处理静态资源(自定义资源映射) 1.17 Spring Boot定时任务的使用 1.18 Spring Boot使用Druid和监控配置 1.19 Spring Boot使用Druid(编程注入) 1.20 Spring Boot普通类调用bean 1.21 使用模板(thymeleaf-freemarker) 1.22 Spring Boot 添加JSP支持 1.23 Spring Boot Servlet 1.24 Spring Boot过滤器、监听器 1.25 Spring Boot 拦截器HandlerInterceptor 1.26 Spring Boot启动加载数据CommandLineRunner 1.27 Spring Boot环境变量读取和属性对象的绑定 1.28 Spring Boot使用自定义的properties 1.29 改变自动扫描的包 1.30 Spring Boot Junit单元测试 1.31 SpringBoot启动时的Banner设置 1.32 Spring boot 文件上传(多文件上传) 1.33 导入时如何定制spring-boot依赖项的版本 1.34 Spring Boot导入XML配置 1.35 Spring Boot使用@SpringBootApplication注解 1.36 Spring Boot 监控和管理生产环境 1.37 Spring Boot的启动器Starter详解 1.38 Spring Boot集成Redis实现缓存机制 1.39 Spring Boot Cache理论篇 1.40 Spring Boot集成EHCache实现缓存机制 1.41 Spring Boot分布式Session状态保存Redis 1.42 Spring Boot Shiro权限管理 1.43 Spring Boot Shiro权限管理 1.44 Spring Boot Shiro权限管理 1.45 Spring Boot Shiro权限管理

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值