赞
踩
大事件后端项目01-----SpringBoot快速入门_大事件springboot项目-CSDN博客
- <parent>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-parent</artifactId>
- <version>2.7.6</version>
- </parent>
- <dependencies>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-jdbc</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.mybatis.spring.boot</groupId>
- <artifactId>mybatis-spring-boot-starter</artifactId>
- <version>2.2.2</version>
- </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>
- </dependencies>
如何使用Maven构建SpringBoot项目-CSDN博客
idea提示不支持发行版本13_idea不支持发行版本13-CSDN博客
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
- spring:
- datasource:
- driver-class-name: com.mysql.cj.jdbc.Driver
- url: jdbc:mysql://ip+端口+库名?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true
- username:
- password:
启动properties就行?
git push --set-upstream origin master
- @Data
- public class Article {
- private Integer id;//主键ID
- @NotEmpty
- @Pattern(regexp = "^\\S{1,10}$")
- private String title;//文章标题
- @NotEmpty
- private String content;//文章内容
- @NotEmpty
- @URL
- private String coverImg;//封面图像
-
- @State
- private String state;//发布状态 已发布|草稿
- @NotNull
- private Integer categoryId;//文章分类id
- private Integer createUser;//创建人ID
- private LocalDateTime createTime;//创建时间
- private LocalDateTime updateTime;//更新时间
- }
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-validation</artifactId>
- </dependency>
- <!--lombok依赖-->
- <dependency>
- <groupId>org.projectlombok</groupId>
- <artifactId>lombok</artifactId>
- </dependency>
- package worldtolingyidianke.demo.bean;
-
-
- import lombok.AllArgsConstructor;
- import lombok.Data;
- import lombok.NoArgsConstructor;
-
- //统一响应结果
- @NoArgsConstructor
- @AllArgsConstructor
- @Data
- public class Result<T> {
- private Integer code;//业务状态码 0-成功 1-失败
- private String message;//提示信息
- private T data;//响应数据
-
- //快速返回操作成功响应结果(带响应数据)
- public static <E> Result<E> success(E data) {
- return new Result<>(0, "操作成功", data);
- }
-
- //快速返回操作成功响应结果
- public static Result success() {
- return new Result(0, "操作成功", null);
- }
-
- public static Result error(String message) {
- return new Result(1, message, null);
- }
- }
- package worldtolingyidianke.demo.exception;
-
- import org.springframework.util.StringUtils;
- import org.springframework.web.bind.annotation.ExceptionHandler;
- import org.springframework.web.bind.annotation.RestControllerAdvice;
- import worldtolingyidianke.demo.bean.Result;
-
- @RestControllerAdvice
- public class GlobalExceptionHandler {
- @ExceptionHandler(Exception.class)
- public Result handleException(Exception e){
- e.printStackTrace();
- return Result.error(StringUtils.hasLength(e.getMessage())? e.getMessage() : "操作失败");
- }
- }
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-validation</artifactId>
- </dependency>
- package com.itheima.utils;
-
- import java.util.HashMap;
- import java.util.Map;
-
- /**
- * ThreadLocal 工具类
- */
- @SuppressWarnings("all")
- public class ThreadLocalUtil {
- //提供ThreadLocal对象,
- private static final ThreadLocal THREAD_LOCAL = new ThreadLocal();
-
- //根据键获取值
- public static <T> T get(){
- return (T) THREAD_LOCAL.get();
- }
-
- //存储键值对
- public static void set(Object value){
- THREAD_LOCAL.set(value);
- }
-
-
- //清除ThreadLocal 防止内存泄漏
- public static void remove(){
- THREAD_LOCAL.remove();
- }
- }
- package com.itheima.mapper;
-
- import com.itheima.pojo.Article;
- import org.apache.ibatis.annotations.Insert;
- import org.apache.ibatis.annotations.Mapper;
-
- import java.util.List;
-
- @Mapper
- public interface ArticleMapper {
- //新增
- @Insert("insert into article(title,content,cover_img,state,category_id,create_user,create_time,update_time) " +
- "values(#{title},#{content},#{coverImg},#{state},#{categoryId},#{createUser},#{createTime},#{updateTime})")
- void add(Article article);
-
-
- List<Article> list(Integer userId, Integer categoryId, String state);
- }
添加插件之后,三个错误就全部解决了
<!--java-jwt坐标--> <dependency> <groupId>com.auth0</groupId> <artifactId>java-jwt</artifactId> <version>4.4.0</version> </dependency>
git@gitee.com:lkc20000416/test-case.git
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。