IDEA创建Spring+SpringMVC+MyBatis(SSM)极简入门(上)
1. 创建项目
2. 添加Controller
3. pom+ properties+swager
4. 添加Mysql+ Mybatis
5. 调用Mybatis生成Mapper
1.创建项目
Web+MySQL;
2.添加Controller
默认端口8080
package com.eastmoney.emcc.controller;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/test")
public class TestController {
//<editor-fold desc="Get方法1.普通HTTP参数方式">
/**
* @param yourName 测试名称
* @return helloYouName
*/
@ApiOperation(value = "你的名字", notes = "根据传入名字返回hello to you!")//api简述,详细内容
//访问路径,访问方式 | http://localhost:8080/test/sayHelloToYou?yourName=gyb
@RequestMapping(value = "/sayHelloToYou", method = RequestMethod.GET)//普通HTTP参数GET方式
public String sayHelloToYou(@RequestParam String yourName) {
return "hello " + yourName;
}
//</editor-fold>
//<editor-fold desc="Get方法2.RestFul标准实现">
@ApiOperation(value = "你的生日年", notes = "根据传入生日年返回2019年岁数!")//api简述,详细内容
//http://localhost:8080/test/yourAgeTest/1 |RestFul标准实现
@RequestMapping(value = "/yourAgeTest/{yourBirthYear}", method = RequestMethod.GET)//RestFul标准实现,必填
public Integer countYourAge(@PathVariable(name = "yourBirthYear") Integer yourBirthYear) {
return 2019 - yourBirthYear;
}
//</editor-fold>
}
3.pom+ properties+swager
Mybatis、mapper、pagehelper 三个组件暂时不要开启
配置properties
#current env(dev,test,prod),当前环境
spring.profiles.active=test
#set Spring AOP support,面向切面
spring.aop.auto=true
#set aop-proxy mode: true(cglib) false(java JDK proxy)
#spring.aop.proxy-target-class=true
## server,端口,上下文路径,大小写敏感,http://localhost:8989/emcc/swagger-ui.html#/
server.port=8989
server.servlet.context-path=/emcc
spring.jackson.mapper.accept_case_insensitive_properties=true
#Swagger Configure Properties,swagger2使能设置,包扫描路径目录,swagger-ui标题,描述,版本
emcc.swagger.enable=true
emcc.swagger.packageScan=com.eastmoney.emcc.controller
emcc.swagger.title=Eastmoney Choice Club System API Document
emcc.swagger.description=Summary of emcc api
emcc.swagger.version=1.1
添加Swagger2 configuration
修改TestController
http://localhost:8989/emcc/swagger-ui.html#/
4.添加Mysql+ Mybatis
查看驱动路径
Copy所有表名
解禁pom中的mybatis依赖,添加properties中的配置
添加mybatis-config.XML
添加CommonMapper 、MyMapper、CommonMapper.xml
添加DynamicDataSource和MyBatisSpringConfig
Application类添加包扫描
@MapperScan(basePackages = "com.eastmoney.emcc.dao.mapper", markerInterface = MyMapper.class)//for mybatis
@SpringBootApplication(scanBasePackages = {"com.eastmoney.emcc"})//for mybatis
添加service及其实现类
添加TestController
运行调试swagger
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
2015-10-15 [No000019]不想背单词?看看游戏能否帮你
2015-10-15 [No000018]都在背单词,为啥学霸那么厉害-如何在一天内记200个单词?
2015-10-15 [No000017]单词拼写记不住?试试这俩方法-单词拼写,怎么记又快又好?
2015-10-15 [No000016]为什么假期计划总是做不到?
2015-10-15 [No000015]坏习惯一大堆?别怕,还有救-坏习惯一堆,怎么好好学习嘛!
2015-10-15 [No000014]听说不背单词,考英语会是这种下场-我们为什么必须背单词?
2015-10-15 [No000000]常用软件测试编译环境声明