h1,h2,h3,h4,h5,h6,p,blockquote { margin: 0; padding: 0 }
body { font-family: "Helvetica Neue", Helvetica, "Hiragino Sans GB", Arial, sans-serif; font-size: 13px; line-height: 18px; color: #737373; margin: 10px 13px 10px 13px }
a { color: #0069d6 }
a:hover { color: #0050a3; text-decoration: none }
a img { border: none }
p { margin-bottom: 9px }
h1,h2,h3,h4,h5,h6 { color: #404040; line-height: 36px }
h1 { margin-bottom: 18px; font-size: 30px }
h2 { font-size: 24px }
h3 { font-size: 18px }
h4 { font-size: 16px }
h5 { font-size: 14px }
h6 { font-size: 13px }
hr { margin: 0 0 19px; border: 0; border-bottom: 1px solid #ccc }
blockquote { padding: 13px 13px 21px 15px; margin-bottom: 18px; font-family: georgia, serif; font-style: italic }
blockquote::before { content: "?C"; font-size: 40px; margin-left: -10px; font-family: georgia, serif; color: #eee }
blockquote p { font-size: 14px; font-weight: 300; line-height: 18px; margin-bottom: 0; font-style: italic }
code,pre { font-family: Monaco, Andale Mono, Courier New, monospace }
code { background-color: #fee9cc; color: rgba(0, 0, 0, 0.75); padding: 1px 3px; font-size: 12px }
pre { display: block; padding: 14px; margin: 0 0 18px; line-height: 16px; font-size: 11px; border: 1px solid #d9d9d9; white-space: pre-wrap }
pre code { background-color: #fff; color: #737373; font-size: 11px; padding: 0 }
spring boot + mybatis 环境搭建
- maven 项目的jar包引入
<dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>1.2.2</version> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.2.8</version> </dependency> <dependency> <groupId>org.apache.tomcat</groupId> <artifactId>tomcat-jdbc</artifactId> </dependency> <dependency> <groupId>com.oracle</groupId> <artifactId>ojdbc6</artifactId> <version>11.2.0.1.0</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.1.43</version> </dependency> </dependencies>
- 构造maven项目结构
-
Java |_contrille 控制层 |_mapper 存放DAO 运用的是mybatis所以存放的都是接口 |_model 实体类 |_services 业务层 |_Application.java 是 springBoot 启动入口 resources |_mybatis 存放mapper.xml 配置文件 ,主要的是读取这个文件过后创 建DAO的实现类 |_templates 存放页面 |_Application.properties 配置文件 数据库连接参数
- Application.java 入口类
@EnableAutoConfiguration /*读取配置文件的路劲,在启动的时候自动加载该路径下的类到Spring容器中*/ @SpringBootApplication @ComponentScan /*扫描 具有 Controller,services,repository注解的类到容器中*/ @MapperScan("com.youer.shop.inventory.mapper") /*直接指定要扫描的mapper,这样在mapper接口上就不用一个个加@Mapper*/ public class Application { @Bean @ConfigurationProperties(prefix="spring.datasource") /*加载配置信息,Application.porperties*/ public DataSource dataSource() { return new org.apache.tomcat.jdbc.pool.DataSource(); } @Bean /*数据连接*/ public SqlSessionFactory sqlSessionFactoryBean() throws Exception { SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); sqlSessionFactoryBean.setDataSource(dataSource()); PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); sqlSessionFactoryBean.setMapperLocations(resolver.getResources("classpath:/mybatis/*.xml")); return sqlSessionFactoryBean.getObject(); } @Bean /*事务*/ public PlatformTransactionManager transactionManager() { return new DataSourceTransactionManager(dataSource()); } public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
- mapper.xml 的格式
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.youer.shop.inventory.mapper.UserMapper"> </mapper>
- 后续奖和redis整合 搭建一个分布式换成架构
redis依赖 <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> </dependency>
原文地址:https://www.cnblogs.com/youer66/p/10180253.html