springboot
https://baike.baidu.com/item/Spring%20Boot/20249767?fr=aladdin
Springboot
https://spring.io/projects/spring-boot/
Building a RESTful Web Service
https://spring.io/guides/gs/rest-service/
https://start.spring.io/
https://start.spring.io/
在线工具生成的一个Springboot项目:
然后用idea打开我们的项目名为demo的springboot项目:
https://blog.csdn.net/qq_45171544/article/details/125975987
https://blog.csdn.net/weixin_42072280/article/details/110388852
点击next:
点击next:
点击next:
点击finish。
4.0.0
org.springframework.boot
spring-boot-starter-parent
2.7.4
com.aaa.demo
springboot_ktlx_0930
0.0.1-SNAPSHOT
springboot_ktlx_0930
Demo project for Spring Boot
1.8
org.springframework.boot
spring-boot-starter-thymeleaf
org.springframework.boot
spring-boot-starter-web
org.mybatis.spring.boot
mybatis-spring-boot-starter
2.2.2
mysql
mysql-connector-java
runtime
org.projectlombok
lombok
true
org.springframework.boot
spring-boot-starter-test
test
org.springframework.boot
spring-boot-maven-plugin
org.projectlombok
lombok
#配置服务器端口号
server.port=8088
#配置服务器请求路径
server.servlet.context-path=/aaa
#配数据库连接(数据源)
#驱动类
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
#用户名
spring.datasource.username=root
#密码
spring.datasource.password=123456
#连接字符串
spring.datasource.url=jdbc:mysql://localhost:3306/0716_sboot_db?useSSL=false
#配置mybatis相关内容
#配置mapper文件的位置
mybatis.mapper-locations=classpath:com/mapper/*.xml
#配置实体类
mybatis.type-aliases-package=com.entity
#下换线转小驼峰
mybatis.configuration.map-underscore-to-camel-case=true
访问:“ http://localhost:8088/aaa/ ” 将自动匹配“ index.html ”页面;
// _ooOoo_ //
// o8888888o //
// 88" . "88 //
// (| ^_^ |) //
// O\ = /O //
// ____/`---'\____ //
// .' \\| |// `. //
// / \\||| : |||// \ //
// / _||||| -:- |||||- \ //
// | | \\\ - /// | | //
// | \_| ''\---/'' | | //
// \ .-\__ `-` ___/-. / //
// ___`. .' /--.--\ `. . ___ //
// ."" '< `.___\_<|>_/___.' >'"". //
// | | : `- \`.;`\ _ /`;.`/ - ` : | | //
// \ \ `-. \_ __\ /__ _/ .-` / / //
// ========`-.____`-.___\_____/___.-`____.-'======== //
// `=---=' //
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ //
// 佛祖保佑 永无BUG 永不修改 //
注意:这里因为配置的原因,重新创建了Maven项目
package com.aaa.demo.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("/test")
public class TestController {
@RequestMapping("/show")
public String show(){
//跳转到templates下的test.html
return "test";
}
}
package com.aaa.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class,args);
}
}
Title
这是测试页面
#配置服务器端口号
#server.port=8088
#配置服务器请求路径
#server.servlet.context-path=/aaa
#配数据库连接(数据源)
#驱动类
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
#用户名
spring.datasource.username=root
#密码
spring.datasource.password=123456
#连接字符串
spring.datasource.url=jdbc:mysql://localhost:3306/0716_sboot_db?useSSL=false
#配置mybatis相关内容
#配置mapper文件的位置
mybatis.mapper-locations=classpath:com/mapper/*.xml
#配置实体类
mybatis.type-aliases-package=com.entity
#下换线转小驼峰
mybatis.configuration.map-underscore-to-camel-case=true
// _ooOoo_ //
// o8888888o //
// 88" . "88 //
// (| ^_^ |) //
// O\ = /O //
// ____/`---'\____ //
// .' \\| |// `. //
// / \\||| : |||// \ //
// / _||||| -:- |||||- \ //
// | | \\\ - /// | | //
// | \_| ''\---/'' | | //
// \ .-\__ `-` ___/-. / //
// ___`. .' /--.--\ `. . ___ //
// ."" '< `.___\_<|>_/___.' >'"". //
// | | : `- \`.;`\ _ /`;.`/ - ` : | | //
// \ \ `-. \_ __\ /__ _/ .-` / / //
// ========`-.____`-.___\_____/___.-`____.-'======== //
// `=---=' //
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ //
// 佛祖保佑 永无BUG 永不修改 //
4.0.0
org.springframework.boot
spring-boot-starter-parent
2.7.4
org.example
springboot_ktlx2_0930
1.0-SNAPSHOT
8
8
org.springframework.boot
spring-boot-starter-thymeleaf
org.springframework.boot
spring-boot-starter-web
org.mybatis.spring.boot
mybatis-spring-boot-starter
2.2.2
mysql
mysql-connector-java
runtime
org.projectlombok
lombok
true
org.springframework.boot
spring-boot-starter-test
test
package com.aaa.demo.entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
@Data
public class Emp {
private Integer empId;
private String empName;
private String sex;
@DateTimeFormat(pattern = "yyyy-MM-dd")
@JsonFormat(pattern = "yyyy-MM-dd")
private Date birthday;
}
package com.aaa.demo.mapper;
import com.aaa.demo.entity.Emp;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface EmpMapper {
List listAll();
}
package com.aaa.demo.service;
import com.aaa.demo.entity.Emp;
import java.util.List;
public interface IEmpService {
List listAll();
}
package com.aaa.demo.service.impl;
import com.aaa.demo.entity.Emp;
import com.aaa.demo.mapper.EmpMapper;
import com.aaa.demo.service.IEmpService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service
public class EmpServiceImpl implements IEmpService{
@Resource
private EmpMapper empMapper;
@Override
public List listAll() {
return empMapper.listAll();
}
}
package com.aaa.demo.controller;
import com.aaa.demo.entity.Emp;
import com.aaa.demo.service.IEmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping("/emp")
public class EmpController {
@Autowired
private IEmpService empService;
@GetMapping("/list")
public List list(){
return empService.listAll();
}
}
#配置服务器端口号
#server.port=8088
#配置服务器请求路径
#server.servlet.context-path=/aaa
#配数据库连接(数据源)
#驱动类
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
#用户名
spring.datasource.username=root
#密码
spring.datasource.password=123456
#连接字符串
spring.datasource.url=jdbc:mysql://localhost:3306/0927_ssm_vue_db?useSSL=false
#配置mybatis相关内容
#配置mapper文件的位置
mybatis.mapper-locations=classpath:com/mapper/*.xml
#配置实体类
mybatis.type-aliases-package=com.aaa.demo.entity
#下换线转小驼峰
mybatis.configuration.map-underscore-to-camel-case=true
server:
port: 8080
servlet:
context-path: /
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/0927_ssm_vue_db?useSSL=false&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
username: root
password: 123456
mybatis:
mapper-locations: classpath:com/mapper/*.xml
type-aliases-package: com.aaa.demo.entity
configuration:
map-underscore-to-camel-case: true
注意:clean后直接重启项目即可。(如果clean之后,compile将会出错)