标签:容器 pos dal 实体 数据 back neu ref 一个个
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依赖
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</dependency>
标签:容器 pos dal 实体 数据 back neu ref 一个个
原文地址:https://www.cnblogs.com/youer66/p/10180253.html