项目结构

POM模板

<?xml version="1.0" encoding="UTF-8"?>

<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">
<parent>
<artifactId>ssm</artifactId>
<groupId>com.etc</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion> <artifactId>chapter01</artifactId>
<packaging>war</packaging> <name>chapter01 Maven Webapp</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties> <dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.13</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.6</version>
</dependency>
</dependencies> <build>
<finalName>chapter01</finalName>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin> <!-- 查看源代码 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>verify</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin> <!-- 查看文档 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin> </plugins>
</pluginManagement> <!--引入资源文件:包括dao下的mapper.xml文件-->
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
</project>

  

database.properties

driver=com.mysql.cj.jdbc.Driver
url=jdbc\:mysql\://localhost:3306/#?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false&allowPublicKeyRetrieval=true
username=#
password=#

  

mybatis配置文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<!-- 引入数据库属性配置文件 -->
<properties resource="database.properties"/>
<!--<properties>-->
<!--<property name="driver" value="com.mysql.jdbc.Driver" />-->
<!--<property name="url" value="jdbc:mysql://localhost:3306/#" />-->
<!--<property name="username" value="#" />-->
<!--<property name="password" value="#" />-->
<!--</properties>-->
<!--配置mybatis的日志处理:Log4j -->
<settings>
<setting name="logImpl" value="LOG4J"/>
</settings>
<typeAliases>
<!-- <typeAlias alias="user" type="com.etc.entity.User" /> -->
<package name="com.etc.entity"/>
</typeAliases>
<!--设置mybatis的运行环境,通过过default指定其中一种环境-->
<environments default="development">
<environment id="development">
<!--使用JDBC事务管理-->
<transactionManager type="JDBC"/>
<!--使用mybatis数据源POOLED-->
<dataSource type="POOLED">
<property name="driver" value="${driver}"/>
<property name="url" value="${url}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>
</dataSource>
</environment>
<environment id="jnditest">
<!--使用JDBC事务管理-->
<transactionManager type="JDBC"/>
<!--使用JNDI数据源,JNDI需要在tomcat配置文件中进行配置-->
<dataSource type="JNDI">
<property name="data_source" value="java:comp/env/jndi/mybatis"/>
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource="com/etc/dao/UserMapper.xml"/>
</mappers>
</configuration>

  

配置文件节点的出现有顺序,否则配置文件会报错。

  

mybaitis映射文件

<?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.etc.dao.UserMapper">
<!-- 统计用户表人数 -->
<select id="count" resultType="int">
SELECT COUNT(1) as count FROM smbms_user
</select> <select id="listUser" resultType="User">
SELECT * FROM smbms_user
</select> </mapper>

  

DAO

package com.etc.dao;

import java.util.List;

import com.etc.entity.User;

public interface UserMapper {

	/** 统计用户人数 */
int count(); /** 查询全部用户 */
List<User> listUser(); }

  

最新文章

  1. Linux安装MySQL
  2. 什么是CGI、FastCGI、PHP-CGI、PHP-FPM、Spawn-FCGI?
  3. 扩展AuthorizeAttribute
  4. Windows 8 一起学习
  5. Connect模块解析
  6. window.event
  7. Microsecond and Millisecond C# Timer[转]
  8. iConvert Icons 图标转换生成利器,支持Windows, Mac OS X, Linux, iOS,和Android等系统
  9. MySQL show status详解
  10. 监视系统3389的VBS脚本
  11. delphi之完美Splash方案(在TfrmMain.FormCreate里不断调用TfrmSplash显示加载进度文字,并且及时Update显示)
  12. 使用JavaScript把页面上的表格导出为Excel文件
  13. 使用cocoapods的两个大坑的修改方法
  14. iOS10适配——错误:Code=3000
  15. UVa 10812 - Beat the Spread!
  16. 基于Redis位图实现系统用户登录统计
  17. vue的高阶组件
  18. scrapy之基础概念与用法
  19. RESTful API 设计思考
  20. centos下查看python的安装目录

热门文章

  1. Shaderlab blend
  2. 洛谷P3688/uoj#291. [ZJOI2017]树状数组
  3. [Xcode 实际操作]六、媒体与动画-(11)UIView视图卷曲动画的制作
  4. atom 插件 python语法验证linter-flake8-------填坑
  5. spring 公用异常处理
  6. 查看java版本
  7. mac 增加/usr/bin目录的操作无权限
  8. redis之安装
  9. 牛客小白月赛13 G(双向搜索)
  10. shell 发送Post请求,并获取状态码