新手使用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. 轻松解除官方对博客后台设置页面3段html代码的限制:iframe alert flagcounter etc.的禁用

    今天我发现我的flagcounter不能用了 iframe也不能用了,无奈╮(╯_╰)╭ 第一反应是Ctrl U viewsource看看源码出了什么问题 结果竟然是这样, 因为页首和侧边栏的html ...

  2. jq js 获取子元素

    js this.children[1].className=""this.firstChild.className = ""this.lastChild.cla ...

  3. CSP-J2019 把8个同样的球放在同样的5个袋子里,允许有的袋子空着不放,问共有多少种不同的分法?

    把8个同样的球放在同样的5个袋子里,允许有的袋子空着不放,问共有多少种不同的分法? 提示:如果8个球都放在一个袋子里,无论是放哪个袋子,都只算同一种分法. 解析: 把问题合成,先思索5个袋子都不空的状 ...

  4. 弱校验之@NotNull@NotEmpty@NotBlank

    @NotNull 适用于非空判断 The annotated element must not be {@code null}. CharSequence, Collection, Map 和 Arr ...

  5. SVG的引入历程

    直接引入编辑器会报错 Google: typescript svg cannot find module找到 这个网址 我放到了 shims-vue.d.ts 里面 declare module &q ...

  6. Java 将Html转为PDF

    本文介绍如何在Java程序中将html文件转换成PDF文件.转换时,需要注意以下两点: 一.需要使用转换插件 可根据不同的系统来下载对应的插件,下载地址:windows-x86.zip, window ...

  7. influxDB初步学习

    influxdb的安装等操作在我的文章. 首先得装influxdb,其次操作如下. application.properties spring.datasource.test1.jdbc-url=jd ...

  8. mybatis逆向工程介绍

    项目的model一旦多了起来,复杂了起来,我们很自然的想到使用mybatis的逆向工程来生成相应的pojo和mapper,能节省很多精力. MyBatis Generator(MBG)是 MyBati ...

  9. springboot-swagger配置

    原文地址 https://www.cnblogs.com/softidea/p/6251249.html https://www.cnblogs.com/xiebq/p/9181517.html 1p ...

  10. e3mall商城的归纳总结1之项目的架构

    首先来谈谈e3mall商城,e3mall商城是黑马推出一个学习的项目,前身是淘淘商城.两个用的技术差不多.,但由于后期加了一些新技术,更名为e3mall商城.本商城为分布式商城,主要用到的技术使mav ...