标签:ext 目的 注册表 stat vax and default sql 规范
JNDI:Java Naming and Directory Interface 时 SUN 公司推出的一套规范,属于 JavaEE 技术之一。目的时模仿 windows 系统中的注册表
<!-- https://mvnrepository.com/artifact/org.mortbay.jetty/servlet-api -->
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>servlet-api</artifactId>
<version>3.0.20100224</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet/jsp-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<?xml version="1.0" encoding="utf-8" ?>
<!--
name="jdbc/eesy_mybatis" 数据源名称
type="javax.sql.DataSource" 数据源类型,要存储的对象类型
auth="Container" 数据源提供者
maxActive="20" 最大活动数,最大活动连接
maxWait="10000" 最大等待时间(秒)
maxIdle="5" 最大空闲数
username="root" 用户名
password="root" 密码
driverClassName="com.mysql.jdbc.Driver" 驱动类
url="jdbc:mysql://localhost:3306/eesy_mybatis" 连接 url 字符串
-->
<Context>
<Resource
name="jdbc/test"
type="javax.sql.DataSource"
auth="Container"
maxActive="20"
maxWait="10000"
maxIdle="5"
username="root"
password="root"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/test"
/>
</Context>
<?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="jdbcConfig.properties"/>
<typeAliases>
<package name="domain"/>
</typeAliases>
<environments default="mysql">
<environment id="mysql">
<transactionManager type="JDBC"/>
<dataSource type="JNDI">
<property name="data_source" value="java:comp/env/jdbc/test"/>
</dataSource>
</environment>
</environments>
<mappers>
<package name="dao"/>
</mappers>
</configuration>
cmd:
netstat -ano|findstr 1099
taskkill -f -pid 3576
编译时:经过 Tomcat server 服务器,会先翻译成java,在编译成class
<%@ page import="java.io.InputStream" %>
<%@ page import="org.apache.ibatis.io.Resources" %>
<%@ page import="org.apache.ibatis.session.SqlSessionFactoryBuilder" %>
<%@ page import="org.apache.ibatis.session.SqlSessionFactory" %>
<%@ page import="org.apache.ibatis.session.SqlSession" %>
<%@ page import="dao.IUserDao" %>
<%@ page import="com.sun.org.apache.bcel.internal.generic.IUSHR" %>
<%@ page import="java.util.List" %>
<%@ page import="domain.User" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<html>
<body>
<h2>Hello World!</h2>
<%
InputStream in= Resources.getResourceAsStream("SqlMapConfig.xml");
SqlSessionFactoryBuilder builder=new SqlSessionFactoryBuilder();
SqlSessionFactory factory=builder.build(in);
SqlSession sqlSession=factory.openSession(true);
IUserDao userDao=sqlSession.getMapper(IUserDao.class);
List<User> users=userDao.findAll();
for (User user:users){
System.out.println("------------------------------");
System.out.println(user);
}
%>
</body>
</html>
标签:ext 目的 注册表 stat vax and default sql 规范
原文地址:https://www.cnblogs.com/zuiren/p/11406133.html