统计
  • 建站日期:2021-03-10
  • 文章总数:3772 篇
  • 评论总数:29 条
  • 分类总数:43 个
  • 最后更新:5月19日
文章 未分类

手把手教你从一无所有到财务自由pdf (手把手教你从0搭建SpringBoot名目)

小菜鸡
首页 未分类 正文

在银行呆了一年,很久没写SpringBoot名目了,搭建一个繁难的SpringBoot名目回忆下用到的工具,idea2021、Maven3.6.3、postman框架,SpringBoot、Mybatis数据库,Mysql8.0.30一、Maven装置&amp,性能装置&amp,性能参考博文留意,1.下载maven留意idea与Mav...。

手把手教你从一无所有到财务自由pdf(手把手教你从0搭建SpringBoot名目)
-IT菜鸡教程网-IT技术博客
-第1
张图片

在银行呆了一年,很久没写SpringBoot名目了,搭建一个繁难的SpringBoot名目回忆下

用到的工具:idea 2021、Maven 3.6.3、postman
框架:SpringBoot、Mybatis
数据库:Mysql8.0.30

一、Maven 装置&性能

装置&性能参考博文

留意:
1.下载maven留意idea与Maven版本的适配:

    IDEA 2022 兼容maven 3.8.1及之前的所用版本IDEA 2021 兼容maven 3.8.1及之前的所用版本IDEA 2020 兼容Maven 3.6.3及之前一切版本IDEA 2018 兼容Maven3.6.1及之前一切版本

2.为了防止每次创立名目都要改Maven性能,可以修正idea创立新名目的设置

二、装置数据库

mysql8装置参考博文

三、设计库表(这里用的idea自带的数据库治理工具,其余诸如Dbeaver、SQLyog等也可以)

**留意:**衔接不上往往是驱动的疑问,把对应的驱动下载好即可

新建表

新建字段

参与数据

留意 :参与成功后须要提交

  • 参与的快捷键:alt+insert
  • 提交的快捷键:ctrl+enter

四、搭建SpringBoot名目

1.创立名目

2. 勾选会用到的依赖


手把手教你从一无所有到财务自由pdf(手把手教你从0搭建SpringBoot名目)
-IT菜鸡教程网-IT技术博客
-第2
张图片#### 3.名目刚创立好时的结构(图片是拷贝的他人的,所以名目名不分歧,别在意,重点关注名目结构即可)

4.templates文件下新建index.html页面,作为启动的初始页面


<html lang="en">
<head><meta charset="UTF-8"><title>Hello</title>
</head>
<body>
SpringBoot 繁难启动页面
</body>
</html>

5. 在com.susu.testsimplespringboot下新建controller文件夹,在controller文件夹下建一个繁难的LoginController类;(Controller类要参与@Controller注解,名目启动时,SpringBoot会智能扫描加载Controller)

package com.susu.testsimplespringboot;import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;/*** @ClassName HelloController* @Description TODO* @Author susu* @Date 2023/4/9 15:53* @Version 1.0*/
@Controller
public class HelloController {@RequestMapping("/index")public String sayHello() {return "index";}
}

6.在resources文件夹下application中先性能DataSource基本消息

application文件有两种文件格局,一种是以**.properties 为后缀,一种是以 .yml**为后缀的,两种性能模式略有差异,概略可参考:https://blog.csdn.net/qq_29648651/article/details/78503853;在这我是用.yml后缀的文件格局。右键application文件选用Refact,选用Rename,将后缀改为yml

spring:>7. 运转名目TestSimpleSpringBootApplication.java(图片是拷贝的,所以文件名不分歧,别在意,重点关注启动类没动过,间接启动即可) 
<p class="quietlee_a3f39_0d88e"></p> 
<h4>8.在阅读器中输入localhost:8080,回车显示初始的index界面</h4> 
<p class="quietlee_14bfa_6bb14"></p> 
<h4>9. SpringBoot 名目大略可以分为以下四层</h4> 
<ul><li class="quietlee_7cbbc_409ec">mapper层(dao层)</li><li class="quietlee_e2c42_0d928">service层(包括service接口、成功类)</li><li class="quietlee_32bb9_0e897">controller层(web层)</li></ul><h4>10.最终的名目结构</h4> 
<p class="quietlee_d2dde_a18f0"></p> 
<h4>11 名目代码展现</h4> 
<p class="quietlee_ad61a_b1432"><strong>(1)在application性能文件中参与:数据库性能、MyBatis性能:</strong></p> 
spring:alt="在这里拔出图片形容" /><br></br><strong>留意!!!</strong> 
<ol><li class="quietlee_fbd79_39d67"> <p class="quietlee_28dd2_c7955">namespace、id的属性值</p> <p class="quietlee_35f4a_8d465"><strong>namespace</strong>:mapper接口名;<br></br><strong>id</strong>:mapper接口中形象方法的名字</p> </li><li class="quietlee_d1fe1_73d08"> <p class="quietlee_f033a_b37c3">mybatis映射文件的一些技术点可参考上方的博文<br></br> https://blog.csdn.net/zxdspaopao/article/details/112919320</p> </li></ol><p class="quietlee_43ec5_17d68"><strong>(6)service接口</strong></p> 
package com.susu.testsimplespringboot.service;import com.susu.testsimplespringboot.pojo.UserLogin;/*** @ClassName UserService* @Description TODO* @Author susu* @Date 2023/4/9 16:27* @Version 1.0*/
public interface UserService {public abstract UserLogin loginCheck(String userAccount, String userPwd);} 
<p class="quietlee_fe9fc_289c3"><strong>(6)service成功类</strong></p> 
package com.susu.testsimplespringboot.serviceImpl;import com.susu.testsimplespringboot.DTO.UserLoginDTO;
import com.susu.testsimplespringboot.service.UserService;
import com.susu.testsimplespringboot.mapper.UserMapper;
import com.susu.testsimplespringboot.pojo.UserLogin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;/*** @ClassName UserServiceImpl* @Description TODO* @Author susu* @Date 2023/4/9 16:37* @Version 1.0*/
@Service
public class UserServiceImpl implements UserService {@AutowiredUserMapper userMapper;@Overridepublic UserLogin loginCheck(String userAccount, String userPwd) {UserLoginDTO userLoginDTO = userMapper.selectUserInfo(userAccount, userPwd);UserLogin userLogin = new UserLogin();if (userLoginDTO != null) {userLogin.setUserAccount(userLoginDTO.getUserAccount());userLogin.setUserPwd(userLoginDTO.getUserPwd());}return userLogin;}
} 
<p class="quietlee_3ef81_5416f"><strong>(7)到此时,可以在测试类测试下Mapper层能否可以反常失掉数据</strong></p> 
package com.susu.testsimplespringboot;import com.susu.testsimplespringboot.pojo.UserLogin;
import com.susu.testsimplespringboot.service.UserService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;@SpringBootTest
class TestSimpleSpringBootApplicationTests {@AutowiredUserService userService;@Testvoid contextLoads() {UserLogin userLogin = userService.loginCheck("huahua", "123");System.out.println(userLogin);}} 
<p class="quietlee_c7e12_49ffc"><strong>(8)controller</strong></p> 
package com.susu.testsimplespringboot.controller;import com.susu.testsimplespringboot.DTO.UserLoginDTO;
import com.susu.testsimplespringboot.pojo.UserLogin;
import com.susu.testsimplespringboot.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;/*** @ClassName LoginController* @Description TODO* @Author susu* @Date 2023/4/9 16:27* @Version 1.0*/
@Controller
//@ResponseBody
public class LoginController {@AutowiredUserService userService;/*** @param testGetStaticSource* @param index* @return*/@RequestMapping("{testGetStaticSource}/{index}")public String getStaticSource(@PathVariable String testGetStaticSource, @PathVariable String index) {return testGetStaticSource + "/" + index;}@GetMapping(value = "login")public String login() {return "login";}@GetMapping(value = "loginIn")public String loginGet(String userAccount, String userPwd) {UserLogin user1 = userService.loginCheck(userAccount, userPwd);if (user1 != null) {return "success";} else {return "error";}}@PostMapping(value = "loginIn")public String loginPost(UserLoginDTO userLoginDTO) {UserLogin user1 = userService.loginCheck(userLoginDTO.getUserAccount(), userLoginDTO.getUserPwd());if (user1 != null) {return "success";} else {return "error";}}} 
<p class="quietlee_76479_66b73"><strong>留意:</strong><br></br> 1.@RequestMapping,任何恳求模式都可以<br></br> 2.@GetMapping,只能Get恳求(前端恳求模式如下所示)<br></br></p> 
<p class="quietlee_86139_85ec4">3.@PostMapping,只能Post恳求<br></br> 3.1 用postman发送post恳求参考博文<br></br> 3.2前端json格局报文:</p> 
{
"userAccount":"huahua",
"userPwd":"123"
}

<p class="quietlee_92cc2_27532">4.测试了失掉templates文件下的静态资源</p> 
    @RequestMapping("{testGetStaticSource}/{index}")public String getStaticSource(@PathVariable String testGetStaticSource, @PathVariable String index) {return testGetStaticSource + "/" + index;}

<p class="quietlee_f4b9e_c30ad">细节可以参考如下两篇博文<br></br> https://blog.csdn.net/zhuzicc/article/details/105465814#%E9%97%AE%E9%A2%98%E5%8E%9F%E5%9B%A0</p> 
<p class="quietlee_812b4_ba287">https://blog.csdn.net/weixin_53106424/article/details/123502419</p> 
<p class="quietlee_26657_d5ff9">此处触及springmvc的原理:<br></br> 可以参考博文:<br></br> https://blog.csdn.net/weixin_53106424/article/details/115309018?spm=1001.2014.3001.5502</p> 
<p class="quietlee_e2ef5_24fbf"><strong>(9)几个静态文件</strong><br></br> 9.1 login.html</p> 

<html lang="en">
<head><meta charset="UTF-8"><title>login</title>
</head>
<body>
<form role="form" action="/loginIn" method="post">账号:<input type="text" id="userAccount" name="userAccount"><br>明码:<input type="password" id="userPwd" name="userPwd"><br><input type="submit" id="login" value="login">
</form>
</body>
</html>

<p class="quietlee_ac627_ab1cc">9.2 success.html</p> 

<html lang="en">
<head><meta charset="UTF-8"><title>success</title>
</head>
<body>
<h1>登录成功</h1>
</body>
</html>

<p class="quietlee_38b3e_ff8ba">9.3 error.html</p> 

<html lang="en">
<head><meta charset="UTF-8"><title>eoor</title>
</head>
<body>
<h1>登录失败</h1>
</body>
</html>
<link class="quietlee_c2eb8_95db0" href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/markdown_views-f23dff6052.css"></link><link class="quietlee_a628e_9840c" href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/style-c216769e99.css"></link>

版权说明
文章采用: 《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》许可协议授权。
客服邮箱:kefu@itcaiji.cn
版权声明:未标注转载均为本站原创,转载时请以链接形式注明文章出处。如有侵权、不妥之处,请联系站长删除。敬请谅解!

-- 展开阅读全文 --
pycharm怎么改成中文 (Pycharm主机性能方法并联合内网穿透工具成功远程开发 IDE Python)
« 上一篇
cwindowssystem32config不可用 (C#WindowsForm罕用窗体工具)
下一篇 »
为了防止灌水评论,登录后即可评论!

热门文章

1
2
什么是高防CDN
4
推特计划推出点对点支付功能
5
p5.js 3D图形-立方体

标签