【项目创建流程】普通接口开发
创建数据库
创建的时候选择utf8mb4 urf8修改了兼容四字节的字符,解决某些汉字出现乱码问题
utf8_general_ci: 校对速度快,但准确度稍差。
utf8_unicode_ci: 准确度高,但校对速度稍慢。
若数据库中有德语、法语或者俄语需求,需使用utf8_unicode_ci。其他情况用utf8_general_ci即可。
建Maven
改POM
写YML
server:
port: 8140 # 服务端口
spring:
profiles:
active: dev # 环境设置
application:
name: service-cms # 服务名
cloud:
nacos:
discovery:
server-addr: localhost:8848 # nacos服务地址
sentinel:
transport:
port: 8081
dashboard: localhost:8080
datasource: # mysql数据库连接
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/guli_cms?serverTimezone=GMT%2B8
username: root
password: 123456
#spring:
jackson: #返回json的全局时间格式
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
mybatis-plus:
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl #mybatis日志
mapper-locations: classpath:cn/jimu98/guli/service/cms/mapper/xml/*.xml
ribbon:
ConnectTimeout: 10000 #连接建立的超时时长,默认1秒
ReadTimeout: 10000 #处理请求的超时时间,默认为1秒
feign:
sentinel:
enabled: true
主启动
@SpringBootApplication
@ComponentScan({"cn.jimu98.guli"})
public class ServiceEduApplication {
public static void main(String[] args) {
SpringApplication.run(ServiceEduApplication.class, args);
}
}
业务类
@CrossOrigin //解决跨域问题
@RestController
@RequestMapping("/admin/edu/teacher")
public class TeacherController {
@Autowired
private TeacherService teacherService;
@GetMapping("list")
public List<Teacher> listAll(){
return teacherService.list();
}
}
代码生成器
项目经理不让用就自己写吧。。。