新手使用springboot或者说,刚接触java行业,有些不明白的就是项目的架构是怎么样的,我今天在这儿稍微整理了一下

有些新手可能在想,springboot是怎么解决最原始的增-删-改-查,

快速搭建是多么舒服的一件事,哈哈

今天,火浴带大家哎熟悉一下流程

1、首先创建一个springboot的工程

2、点击继续

3、这里可以什么都不选,要是你会的话,可以选

4、改好你的项目名称和路劲后点击完成

5、这是我的maven依赖


<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.1.3</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.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency> <dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.28</version>
</dependency> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

6、这是yml的配置


server:
port: 9000 # mysql
spring:
datasource:
#MySQL\u914D\u7F6E
driverClassName: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/easyproject?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC
username: root
password: root
#mybatis\u914D\u7F6E
mybatis:
mapper-locations: classpath:mapper/*.xml
type-aliases-package: com.example.demo.model

7、我们先介绍查询所有的方法,这是dao层,

添加

public List<User> getAllUser(@Param("username") String username,@Param("pageStart") int pageStart, @Param("pageSize") int pageSize);

8、编写原生xml,里面是mysql的 查询语句


<select id="getAllUser" resultType="com.springboot_sport.entity.User">
SELECT * FROM easyUser
<if test="username !=null ">
WHERE username like #{username}
</if>
LIMIT #{pageStart},#{pageSize}
</select>

9、定义entity类,里面的内容是你查询的数据库的字段

生成get、set方法,可能小伙伴不会,2020版的快捷键是shift+alt+s,,或者你鼠标右键Generate。。。这个也可以看到

10、定义Contronller接口,我用的前端框架是vue的

package com.springboot_sport.controller;

import com.alibaba.fastjson.JSON;
import com.springboot_sport.entity.QueryInfo;
import com.springboot_sport.dao.UserDao;
import com.springboot_sport.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import java.util.HashMap;
import java.util.List; /**
* @author huoyu Email:23198997662@qq.com
* @version v1.0
* @Description
* @create 2020--09--1621:17
*/
@RestController
public class UserController {
@Autowired
private UserDao uDao;
@RequestMapping("/alluser")
public String getUserList(QueryInfo queryInfo){
//获取最大列表数和当前编号
int numbers = uDao.getUserCounts("%" + queryInfo.getQuery() + "%");
int pageStart = (queryInfo.getPageNum() - 1) * queryInfo.getPageSize();
List<User> users = uDao.getAllUser("%" + queryInfo.getQuery() + "%", pageStart, queryInfo.getPageSize());
HashMap<String, Object> res = new HashMap<>();
res.put("unmbers",numbers);
res.put("data",users);
String res_string = JSON.toJSONString(res);
return res_string;
}
} 这样一个查询接口就相当于做完了,我在给大家说一个就是关于springboot+vue的跨域问题怎么解决的 ![](https://img2020.cnblogs.com/blog/1566889/202009/1566889-20200921115941604-1252214819.png) 下面是代码

package com.springboot_sport.util;

import org.springframework.context.annotation.Configuration;

import org.springframework.web.servlet.config.annotation.CorsRegistry;

import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**

  • @author huoyu Email:23198997662@qq.com

  • @version v1.0

  • @Description

  • @create 2020--09--0223:05

    */

    //全局配置类--配置跨域请求

    @Configuration

    public class WebConfig extends WebMvcConfigurerAdapter {

    @Override

    public void addCorsMappings(CorsRegistry registry) {

    registry.addMapping("/**")

    .allowedMethods("")

    .allowedOrigins("
    ")

    .allowedHeaders("*");

    super.addCorsMappings(registry);

    }

    }

好了,完成

新手接触springboot的更多相关文章

  1. 新手接触java

    第二个程序,求同时被3,5,7整除

  2. springboot访问请求404问题

    新手在刚接触springboot的时候,可能会出现访问请求404的情况,代码没问题,但就是404. 疑问:在十分确定代码没问题的时候,可以看下自己的包是不是出问题了? 原因:SpringBoot 注解 ...

  3. 基于springboot搭建的web系统架构

    从接触springboot开始,便深深的被它的简洁性深深的折服了,精简的配置,方便的集成,使我再也不想用传统的ssm框架来搭建项目,一大堆的配置文件,维护起来很不方便,集成的时候也要费力不少.从第一次 ...

  4. SpringBoot+thymeleaf+security+vue搭建后台框架 基础篇(一)

    刚刚接触SpringBoot,说说踩过的坑,主要的还是要记录下来,供以后反省反省! 今天主要讲讲 thymeleaf+security 的搭建,SpringBoot的项目搭建应该比较简单,这里就不多说 ...

  5. 关于springboot项目中自动注入,但是用的时候值为空的BUG

    最近想做一些web项目来填充下业余时间,首先想到了使用springboot框架,毕竟方便 快捷 首先:去这里 http://start.spring.io/ 直接构建了一个springboot初始化的 ...

  6. SpringBoot整合Mybatis完整详细版

    记得刚接触SpringBoot时,大吃一惊,世界上居然还有这么省事的框架,立马感叹:SpringBoot是世界上最好的框架.哈哈! 当初跟着教程练习搭建了一个框架,传送门:spring boot + ...

  7. SpringBoot各类扩展点详解

    一.前言 上篇文章我们深入分析了SpringBoot的一站式启动流程.然后我们知道SpringBoot的主要功能都是依靠它内部很多的扩展点来完成的,那毋容置疑,这些扩展点是我们应该深入了解的,那么本次 ...

  8. SpringBoot初体验及原理解析

    一.前言 ​ 上篇文章,我们聊到了SpringBoot得以实现的幕后推手,这次我们来用SpringBoot开始HelloWorld之旅.SpringBoot是Spring框架对“约定大于配置(Conv ...

  9. SpringBoot配置文件application.properties详解

    喜欢的朋友可以关注下,粉丝也缺. 相信很多的码友在接触springboot时,不知道怎么去配置一些项目中需要的配置,比如数据源,tomcat调优,端口等等,下面我就给大家奉献出一些项目中常用的配置信息 ...

随机推荐

  1. css3 属性 text-overflow 实现截取多余文字内容 以省略号来代替多余内容

    css3 属性 text-overflow: ellipsis 前言 正文 结束语 前言 我们在设计网站的时候有时会遇到这样一个需求:因为页面空间大小的问题,需要将多余的文字隐藏起来,并以省略号代替, ...

  2. SpringCloude简记_part3

    18. SpringCloud Alibaba Sentinel实现熔断与限流 18.1 Sentiel 官网 https://github.com/alibaba/Sentinel 中文 https ...

  3. hook框架-frida简单使用模板以及frida相关接口

    一目录结构 ├── test.py #py脚本 └── test.js #js脚本 一.py脚本 test.py import frida import sys #连接设备app dev=frida. ...

  4. Qt 实现 异形 窗体&按钮

    //关键部分代码如下//设置异形窗体 //setWindowOpacity(0.5);//设置窗体透明度 0完全透明,1完全不透明 this->setWindowFlag(Qt::Framele ...

  5. 手把手教Linux驱动3-之字符设备架构详解,有这篇就够了

    一.Linux设备分类 Linux系统为了管理方便,将设备分成三种基本类型: 字符设备 块设备 网络设备 字符设备: 字符(char)设备是个能够像字节流(类似文件)一样被访问的设备,由字符设备驱动程 ...

  6. Spring是如何解决循环依赖的

    前言 在面试的时候这两年有一个非常高频的关于spring的问题,那就是spring是如何解决循环依赖的.这个问题听着就是轻描淡写的一句话,其实考察的内容还是非常多的,主要还是考察的应聘者有没有研究过s ...

  7. 服务发现Eureka、zookeeper、consul

    Spring Cloud为开发人员提供了工具,以快速构建分布式系统中的某些常见模式(例如,配置管理,服务发现,断路器,智能路由,微代理,控制总线,一次性令牌,全局锁,领导选举,分布式会话,群集状态). ...

  8. eclipse 设置默认编码为Utf-8 详细教程。

    需要设置的几处地方为: Window->Preferences->General ->Content Type->Text->JSP 最下面设置为UTF-8 Window ...

  9. Linux下Vim常用操作

    linux下Vim的常用操作 linux ​ 首先\(ctrl+Alt+t\)打开小框框 ​ \(./\):相当于手机上的\(home\)键 ​ \(ls\):当前文件夹的东东 ​ \(mkdir\) ...

  10. Oracle RAC与DG

    RAC RAC: real application clustersrac RAC: real application clustersrac 单节点数据库:数据文件和示例文件一一对应 实例损坏时数据 ...