spring-boot jpa jsp 框架搭建(一)
开发工具及其环境
1.开发工具 IntelliJ IDEA 2017.2.6
2. 开发环境 JDK 1.8
3. maven
spring-boot 框架搭建
1.创建spring-boot项目
打开IDEA开发工具,点击左上角File->New->Project
选择JDK版本,然后Next
输入Group Artifact 等信息,然后Next
添加依赖,本次spring-boot框架搭建选用的是mysql数据库所以需要勾选的依赖有:web MySQL JPA
最后一步,确认一下项目名称,指定保存地址,Finish
项目创建完成!
在idea里面配置一下本地maven,打开setting,搜索maven,配置成本地的maven
编辑spring-boot配置文件application.properties
配置server,在application.properties添加
server.port=80
配置数据库
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/fvshop?useUnicode=true&characterEncoding=utf-8
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
#服务器端口
server.port=80
##数据库连接信息
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/fvshop?useUnicode=true&characterEncoding=utf-8
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
分包,测试
- 新建web.controller包
- 新建IndexController类
- 书写controller,在IndexController里面写:
package cn.itlaobing.web.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
//此注解默认返回json数据
@RestController
public class IndexController {
@RequestMapping("index")
public String index(){
return "hello world";
}
}
4.启动spring-boot
5.访问,在游览器里面输入 localhost/index