SpringBoot入门之整合mybatis
2017-01-05 10:25
597 查看
新建maven项目
配置pom.xml
编写测试代码
最近闲的无聊,在热潮的推动下,我也来尝试点新鲜东西
2.Bean
3.Mapper类
4.Controller类
5.测试
编写好以上4个类之后,运行application.java(spring boot app),
页面直接访问
配置pom.xml
编写测试代码
最近闲的无聊,在热潮的推动下,我也来尝试点新鲜东西
新建maven项目
创建后的项目:配置pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>SpringBootStart</groupId> <artifactId>SpringBootStart</artifactId> <version>1.0.0</version> <packaging>war</packaging> <name>SpringBootStart</name> <description>Spring Boot project</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.3.2.RELEASE</version> <relativePath /> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.1.1</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> < 4000 groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <skip>true</skip> </configuration> </plugin> </plugins> </build> </project>
编写测试代码
1.程序入口类:Application.javapackage com.sjz.stepone; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
2.Bean
package com.sjz.stepone; public class Userinfor { private Integer user_id; private String username; public Integer getUser_id() { return user_id; } public void setUser_id(Integer user_id) { this.user_id = user_id; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } }
3.Mapper类
package com.sjz.stepone; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; @Mapper public interface UserinforMapper { @Select("SELECT * FROM userinfor WHERE u_sex = #{name}") Userinfor findByName(@Param("name") String name); }
4.Controller类
package com.sjz.stepone; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping({ "/home" }) public class UserController { @Autowired UserinforMapper userMapper; @RequestMapping(value = "/user") @ResponseBody public String user() { Userinfor user = userMapper.findByName("n"); return user.getUsername(); } }
5.测试
编写好以上4个类之后,运行application.java(spring boot app),
页面直接访问
相关文章推荐
- Spring boot入门五 spring mvc spring boot mybatis配置整合
- SpringBoot入门——整合Mybatis
- Spring boot入门,整合mybatis开发案例
- springboot+mybatis整合(入门)
- SpringBoot入门-快速整合Mybatis
- springboot整合Mybatis(一)——入门
- (七)springboot入门之整合Mybatis
- Spring Boot整合mybatis全注解入门教程
- Spring boot入门五 spring mvc spring boot mybatis配置整合
- SSM(Spring+SpringMVC+MyBatis)框架快速整合入门教程
- MyBatis入门(六)---mybatis与spring的整合
- Spring Boot 整合Mybatis(步骤讲解) 附源码
- Spring boot +freemarker+mybatis整合
- Spring MVC入门第2天--Spring、SpringMVC与MyBatis三大框架整合
- Mybatis最入门---整合Spring
- Spring Boot 构建应用——整合 Mybatis
- Spring Boot整合MyBatis
- MyBatis入门第4天--MyBatis与Spring整合及逆向工程
- Redis入门很简单之九【SpringMvc+Mybatis与redis整合让Mybatis管理缓存】
- SpringBoot入门系列:第六篇 mybatis