• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

eclipse下整合springboot和mybatis的方法步骤

springboot 搞代码 4年前 (2022-01-05) 51次浏览 已收录 0个评论

这篇文章主要介绍了eclipse下整合springboot和mybatis的方法步骤,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

1.新建maven项目

先新建一个maven项目,勾选上creat a simple project,填写groupid,artifactid

2.建立项目结构

3.添加依赖

  org.springframework.bootspring-boot-starter-parent2.0.3.RELEASE<!-- lookup parent from repository --> UTF-8UTF-81.8  org.springframework.bootspring-boot-starter org.springframework.bootspring-boot-starter-testtest org.springframework.bootspring-boot-starter-web org.mybatis.spring.bootmybatis-spring-boot-starter1.3.2 mysqlmysql-connector-java junitjunit   org.springframework.bootspring-boot-maven-plugin

4.代码编写

在包的最外层添加启动类

 package com.lee.test; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cache.annotation.EnableCaching; @SpringBootApplication @EnableCaching public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }

实体类

 package com.lee.test.pojo; import org.springframework.stereotype.Component; @Component public class User { private int id; private String name; private String telephone; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getTelephone() { return telephone; } public void setTelephone(String telephone) { this.telephone = telephone; } }

mapper接口

 package com.lee.test.mapper; import java.util.List; import org.apache.ibatis.annotations.Mapper; import com.lee.test.pojo.User; @Mapper public interface UserMapper { List getUser(int id); }

service接口

 package com.lee.test.service; import java.util.List; import com.lee.test.pojo.User; public interface UserService { public List getUser(int id); }

service接口实现

 package com.lee.test.service; import java.util.List; import com.lee.test.pojo.User; public interface UserService { public List getUser(int id); }

controller层

 package com.lee.test.controller; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.Re<strong style="color:transparent">来源gaodaima#com搞(代@码网</strong>questParam; import org.springframework.web.bind.annotation.RestController; import com.lee.test.pojo.User; import com.lee.test.service.UserService; @RestController public class UserController { @Autowired private UserService userService; @RequestMapping("/getUser") public List getUser(@RequestParam("id") int id) { return userService.getUser(id); } }

还有mapper.xml的实现

    select * from t_user where id = #{id} 

最后是一些配置在application.properties中

 spring.datasource.driverClassName=com.mysql.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8 spring.datasource.username=root spring.datasource.password=root mybatis.mapper-locations: classpath:mapper/*.xml

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持gaodaima搞代码网

以上就是eclipse下整合springboot和mybatis的方法步骤的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:eclipse下整合springboot和mybatis的方法步骤

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址