首页 技术 正文
技术 2022年11月23日
0 收藏 930 点赞 3,386 浏览 854 个字

一、编写底层代码

1.demo-common中创建FormatString类

先在默认com.tyh中创建package命名为common

IDEA项目搭建二——使用SpringBoot创建Web层

删除自动生成的app.java,在common包下创建新类

IDEA项目搭建二——使用SpringBoot创建Web层

编写新类中的代码,注意包名是否正确

IDEA项目搭建二——使用SpringBoot创建Web层

2.demo-entity中创建UserEntity类

步骤同上

IDEA项目搭建二——使用SpringBoot创建Web层

3.demo-dao中创建UserDao类

步骤同上

IDEA项目搭建二——使用SpringBoot创建Web层

4.demo-service中创建UserService类

步骤同上

IDEA项目搭建二——使用SpringBoot创建Web层

注:如果无法import其他模块的包,请检查pom.xml依赖是否添加,如果已添加则使用Maven Projects去package一下

二、使用Spring Boot创建Web层

File -> New -> Module

IDEA项目搭建二——使用SpringBoot创建Web层

IDEA项目搭建二——使用SpringBoot创建Web层IDEA项目搭建二——使用SpringBoot创建Web层IDEA项目搭建二——使用SpringBoot创建Web层

创建完成后,先打开demo-parent模块修改pom.xml文件增加demo-web的子模块

IDEA项目搭建二——使用SpringBoot创建Web层

再打开新创建的demp-web模块删除.mvn、test、.gitignore、mvnw、mvnw.cmd文件,打开pom.xml增加业务逻辑层的依赖

IDEA项目搭建二——使用SpringBoot创建Web层

开始创建文件夹结构

1.在src/main/java/com/tyh下创建controller文件夹,用于存放所有的controller类,创建UserController类

IDEA项目搭建二——使用SpringBoot创建Web层

2.在resources/static中创建css、imgs、scripts三个文件夹,如果在idea中三个文件夹创建成子父级关系了,那就从磁盘上找到static文件夹创建对应的三个文件夹即可,有时候idea不能很好地识别我们的意思

3.在resources/templates中创建user文件夹,再创建edit.html文件

文件夹及文件创建完成后如下图

IDEA项目搭建二——使用SpringBoot创建Web层

开始对内部进行编码

1.打开application.properties编写代码server.port=8080指明启动使用的端口

IDEA项目搭建二——使用SpringBoot创建Web层

2.打开UserController编写代码

IDEA项目搭建二——使用SpringBoot创建Web层

3.打开/user/edit.html编写代码

IDEA项目搭建二——使用SpringBoot创建Web层

先打包再启动,打开浏览器输入localhost:8080/user/edit

IDEA项目搭建二——使用SpringBoot创建Web层

能看到渲染后的页面就表示程序正确

IDEA项目搭建二——使用SpringBoot创建Web层

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,993
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,507
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,349
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,135
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,768
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,845