idea上搭建springboot+mybatis项目

idea+springboot+Mybatis搭建web项目
使用idea+springboot+Mybatis搭建一个简单的web项目。
首先新建一个项目;
在这里插入图片描述
在这里选择Maven项目也可以,但是IDEA为我们提供了一种更方便快捷的创建方法,即Spring Initializr。选择后点击Next;
在这里插入图片描述
把项目信息写好,Next;
在这里插入图片描述
按下面三张图勾选设置;

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
最后Finish。
在这里插入图片描述
等待Maven自动加载完成后,最初的项目结构如下图。在Springboot属性文件application.properties中,把数据库连接属性加上,同时可以设置服务端口。
spring.datasource.url = jdbc:mysql://localhost:3306/test
spring.datasource.username = root
spring.datasource.password = root
spring.datasource.driverClassName = com.mysql.jdbc.Driver
#页面热加载
spring.thymeleaf.cache = false
#端口
server.port=8888
在这里插入图片描述
resources目录下,static文件夹是放置各种静态资源,如css,js,img等文件的。templates文件夹则是默认放置网页的。当然也可以更改。
在static文件夹下新建一个测试css,test.css。
body{
color: red;
}
  
在templates文件夹下新建一个html,要注意的是meta这个标签的结束符软件并没有自动加上,需要手动加上,否则访问网页时会报错。并引入test.css

Title

Hello World

 ![在这里插入图片描述](https://img-blog.csdnimg.cn/20190409134007561.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTEyMDcxMTY=,size_16,color_FFFFFF,t_70) ![在这里插入图片描述](https://img-blog.csdnimg.cn/20190409134032939.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTEyMDcxMTY=,size_16,color_FFFFFF,t_70)

接下来可以写一个controller了
package com.example.demo;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class IndexController {
@RequestMapping("/index")
public String index(){
return “hello”;
}

}
  
在这里插入图片描述
完成之后,通过方式1和方式2都可以启动项目
在这里插入图片描述
接下来可以在浏览器中测试了
在这里插入图片描述

如果使用postgresql,application.properties文件的写法如下所示:

数据库访问配置

主数据源,默认的

spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url = jdbc:postgresql://192.168.0.110:5432/test2
spring.datasource.username = postgres
spring.datasource.password = Aa123456
#页面热加载
spring.thymeleaf.cache = false
#端口
server.port=8080
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值