Idea Springboot+druid+mybits+MySql

【Idea】Springboot+druid+mybits+MySql简单Springboot工程创建

1.进入idea–>File–>New–>project–>spring Initializer–>default–>选择Mysql及mybatis–>输入项目名称
2.创建新文件application.yml作为新配置文件
3.项目结构:
在这里插入图片描述
4.文件配置:
1)配置端口号及项目默认访问路径
在这里插入图片描述
2)配置Mysql连接
在这里插入图片描述
3)配置DruId连接池(在Spring标签下)
在这里插入图片描述
4)配置Mybatis
在这里插入图片描述
5.启动类
@SpringBootApplication
@MapperScan(“com.hpe.cmca.springboot.mapper”)//扫描接口路径
public class CmcaApplication {

public static void main(String[] args) {
SpringApplication.run
(CmcaApplication.class, args);
}
}
6.测试项目:
① Controller
在这里插入图片描述
② Service
@Service
public class PersonService {

@Resource
private PersonMapper personMapper ;

public List<Person> personInfo(){
    return personMapper.personInfo() ;
}

}
③ Mapper
在这里插入图片描述
④ Mapper.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!-- 根据主键查询-->
<select id="personInfo" resultMap="person"  >
    select  *
    from sys_spring_user
</select>
7.Run CmcaApplication

8.测试接口返回:JSON
http://127.0.0.1:8080/cmca/personInfo
[
{
“id”:1,
“userName”:“小张”,
“age”:“13”
},
{
“id”:2,
“userName”:“小朱”,
“age”:“13”
},
{
“id”:3,
“userName”:“小李”,
“age”:“14”
},
{
“id”:4,
“userName”:“小王”,
“age”:“15”
},
{
“id”:5,
“userName”:“小黑”,
“age”:“14”
}
]

9.注意:
1)如果Spring项目启动访问页面显示WhileLable Error Page,表示Spring Boot启动类,必须需位于包含所有其他类的包中,比其他类的包高一层级。
2)Springboot自带Json转化,可直接返回Map格式数据,但如果当前某一属性为时间时会转化为时间戳,因此,yml内Spring标签下需增加jackson配置
jackson:
time-zone: GMT+8 #表示东八区
date-format: yyyy-MM-dd HH:mm:ss #返回时间

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值