前言

自己是在CentOS7的IntelliJ IDEA里开发的,里面中文输入法有问题经常用不了,所以这里用了很多chinglish,希望不要介意;

一: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">
<modelVersion>4.0.0</modelVersion> <groupId>me.silentdoer</groupId>
<artifactId>combine-spring-struts2-mybatis</artifactId>
<version>1.0-SNAPSHOT</version> <properties>
<spring.group>org.springframework</spring.group>
<spring.version>4.3.4.RELEASE</spring.version> <logback.group>ch.qos.logback</logback.group>
<logback.version>1.2.3</logback.version> <slf4j.group>org.slf4j</slf4j.group>
<slf4j.version>1.7.25</slf4j.version> <mybatis.group>org.mybatis</mybatis.group>
<mybatis.version>3.4.4</mybatis.version>
<mybatis-spring.version>1.3.1</mybatis-spring.version> <mysql.group>mysql</mysql.group>
<mysql-connector.version>5.1.41</mysql-connector.version> <alibaba.group>com.alibaba</alibaba.group>
<druid.version>1.1.6</druid.version>
<fastjson.version>1.2.41</fastjson.version> <dom4j.group>dom4j</dom4j.group>
<dom4j.version>1.6.1</dom4j.version> <junit.group>junit</junit.group>
<junit.version>4.12</junit.version>
</properties> <dependencies>
<!-- spring -->
<dependency>
<groupId>${spring.group}</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
<!-- scope 默认是compile的 -->
<scope>compile</scope>
</dependency>
<dependency>
<groupId>${spring.group}</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>${spring.group}</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>${spring.group}</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>${spring.group}</groupId>
<artifactId>spring-expression</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>${spring.group}</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>${spring.group}</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.10</version>
</dependency> <!-- struts2 -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.3.20</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-convention-plugin</artifactId>
<version>2.3.20</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-spring-plugin</artifactId>
<version>2.3.20</version>
</dependency> <!-- database begin -->
<dependency>
<groupId>${mybatis.group}</groupId>
<artifactId>mybatis</artifactId>
<version>${mybatis.version}</version>
</dependency>
<dependency>
<groupId>${mybatis.group}</groupId>
<artifactId>mybatis-spring</artifactId>
<version>${mybatis-spring.version}</version>
</dependency>
<dependency>
<groupId>${mysql.group}</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql-connector.version}</version>
</dependency>
<dependency>
<groupId>${alibaba.group}</groupId>
<artifactId>druid</artifactId>
<version>${druid.version}</version>
</dependency>
<!-- database end --> <!-- tool begin -->
<dependency>
<groupId>${alibaba.group}</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>
<dependency>
<groupId>${dom4j.group}</groupId>
<artifactId>dom4j</artifactId>
<version>${dom4j.version}</version>
</dependency>
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.9</version>
</dependency> <!-- log begin -->
<dependency>
<groupId>${slf4j.group}</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>${logback.group}</groupId>
<artifactId>logback-core</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>${logback.group}</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
<!-- log end --> <dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>3.1</version>
</dependency> <dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.2</version>
</dependency> <dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency> <!-- 用于测试 begin -->
<dependency>
<groupId>${spring.group}</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${junit.group}</groupId>
<artifactId>junit</artifactId>
<!-- version据说还可以是一个范围值 -->
<version>${junit.version}</version>
<!-- 表示这个jar包是用于测试,打包时不会将此jar包打包进去 -->
<scope>test</scope>
</dependency>
<!-- 用于测试 end --> <!-- 依赖jar包依赖的组件 begin-->
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
<!-- compile 表示编译时和运行时都需要(但IDE可能有bug,不行的话还是自己主动将jar包放到lib目录 -->
<scope>compile</scope>
</dependency> <!-- mq and cache -->
<!--<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>com.rabbitmq</groupId>
<artifactId>amqp-client</artifactId>
<version>4.1.0</version>
</dependency>-->
</dependencies> <build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build> </project>

二:配置web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1"> <!--spring-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <!-- other filters --> <!--struts2, use with last filter-->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>

三:配置struts2/mybatis/spring/mapper配置文件

注:均放在resources目录里

1.struts.xml

(struts1和2都可以用这个名字,struts2会自动加载就像logback.xml一样)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd"> <struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false" /> <!-- use development mode, when exception occur will show in the response body -->
<constant name="struts.devMode" value="true" /> <!-- ke yi bu yao -->
<!--<constant name="struts.objectFactory" value="spring" />-->
<constant name="struts.i18n.encoding" value="utf-8" /> <!-- use to separate diff func action, extends is important for link struts2-spring -->
<!-- namespace like RequestMapping on controller -->
<!-- if namespace is /, then http://localhost:8090/getStudent?uid=1, if namespace is /entity, ..8090/entity/getStudent?uid=1 -->
<package name="entity-resolver" extends="struts-default" namespace="/entity">
<!-- name is in Struts registry key&context/student, class is the action class or spring beanName -->
<!-- method attr is for special method to be handlerMethod -->
<action name="getStudent" class="studentAction">
<result name="success">/WEB-INF/content/vo/student.jsp</result>
<result name="error">/WEB-INF/content/common/error.jsp</result>
</action>
</package> <package name="index" extends="struts-default" namespace="/">
<!-- Struts2 process url also bu xu yao suffix -->
<action name="index" class="indexAction">
<result name="success">/index.html</result>
</action>
</package> <!--<package name="about-permission" extends="struts-default"></package>--> </struts>

2.mybatis-config.xml

<?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>
<typeAliases>
<typeAlias type="me.silentdoer.ssmdemo.pojo.Student" alias="User"/>
</typeAliases> <!--<environments default="development">
<environment id="development">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/db_test"/>
<property name="username" value="test"/>
<property name="password" value="test"/>
</dataSource>
</environment>
</environments>--> <mappers>
<!-- must absolute path -->
<mapper resource="config/mybatis/mapper/StudentMapper.xml"/>
</mappers>
</configuration>

3.applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <!--<tx:annotation-driven transaction-manager="txManager" />--> <!--配置事务管理器-->
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean> <!-- transaction -->
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="select*" read-only="true"/>
<tx:method name="insert*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice> <!-- first * is all visit qualifier -->
<!-- aop -->
<aop:config>
<aop:pointcut id="pointcut" expression="execution(* me.silentdoer.ssmdemo.dao.impl.StudentDaoImpl.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="pointcut"/>
</aop:config> <!-- datasource, can be replace with Druid -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/db_test"/>
<property name="username" value="test"/>
<property name="password" value="test"/>
</bean> <!-- 配置sessionFacfory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 加载dataSource -->
<property name="dataSource" ref="dataSource"/>
<!--加载usermapper.xml-->
<property name="configLocation" value="classpath:mybatis-config.xml"/>
</bean> <context:component-scan base-package="me.silentdoer.ssmdemo">
<!-- exclude by regex, also can use aspectj ex to exclude -->
<context:exclude-filter type="regex" expression="me.silentdoer.ssmdemo.pojo..*"/>
</context:component-scan> <!-- userDao, it's extends SqlSessionDapSupport -->
<!--<bean id="studentDao" class="me.silentdoer.ssmdemo.dao.impl.StudentDaoImpl">
&lt;!&ndash; in setSqlsessionFactory method: this.sqlSession = new SqlSessionTemplate(sqlSessionFactory) &ndash;&gt;
<property name="sqlSessionFactory" ref="sqlSessionFactory"/>
</bean>--> <!--userService-->
<!--<bean id="studentService" class="me.silentdoer.ssmdemo.service.impl.StudentServiceImpl">
<property name="studentDao" ref="studentDao"/>
</bean>--> <!--userAction-->
<!--<bean id="userAction" class="me.silentdoer.ssmdemo.action.student.StudentAction">
<property name="studentService" ref="studentService"/>
</bean>-->
</beans>

4.StudentMapper.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="me.silentdoer.ssmdemo.pojo.StudentMapper">
<resultMap id="studentResultMap" type="me.silentdoer.ssmdemo.pojo.Student">
<id property="uid" column="uid"/>
<result property="name" column="name"/>
<result property="gender" column="gender"/>
<result property="createTime" column="create_time"/>
<result property="updateTime" column="update_time"/>
</resultMap> <!--<insert id="insertOne">
insert into student(name values (#{name})
</insert>--> <select id="selectOne" resultMap="studentResultMap">
select uid, name, gender, create_time, update_time from student where uid=#{uid}
</select>
</mapper>

四:代码实现

1.pojo层的编码

package me.silentdoer.ssmdemo.pojo;

import java.io.Serializable;
import java.sql.Timestamp; /**
* @author silentdoer
* @version 1.0
* @description the description
* @date 4/21/18 2:11 PM
*/
public class Student implements Serializable {
private long uid;
private String name;
private int gender;
private Timestamp createTime; // Timestamp is implements java.util.Date
private Timestamp updateTime; public long getUid() {
return uid;
} public void setUid(long uid) {
this.uid = uid;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public int getGender() {
return gender;
} public void setGender(int gender) {
this.gender = gender;
} public Timestamp getCreateTime() {
return createTime;
} public void setCreateTime(Timestamp createTime) {
this.createTime = createTime;
} public Timestamp getUpdateTime() {
return updateTime;
} public void setUpdateTime(Timestamp updateTime) {
this.updateTime = updateTime;
} @Override
public String toString(){
return String.format("[uid=%s, name=%s, gender=%s, createTime=%s, updateTime=%s]", this.uid, this.name, this.gender, this.createTime, this.updateTime);
}
}

2.dao层的编码

package me.silentdoer.ssmdemo.dao;

import me.silentdoer.ssmdemo.pojo.Student;
import org.apache.ibatis.annotations.Param; /**
* @author silentdoer
* @version 1.0
* @description the description
* @date 4/21/18 1:40 PM
*/
public interface StudentDao {
Student selectOne(@Param("uid") long uid);
}
package me.silentdoer.ssmdemo.dao.impl;

import me.silentdoer.ssmdemo.dao.StudentDao;
import me.silentdoer.ssmdemo.pojo.Student;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository; import javax.annotation.Resource; /**
* @author silentdoer
* @version 1.0
* @description the description
* @date 4/21/18 2:31 PM
*/
// this.sqlSessionProxy.selectOne(statement), proxy will use invoke method to call sqlSessionFactory.openSession();
// this session is sqlSession = new SqlSessionTemplate(sqlSessionFactory); not real SqlSession, in template use proxy to exec
@Repository("studentDao") // default singleton, but in the inside it's will use SqlSessionFactory to openSession(), so can be singleton.
public class StudentDaoImpl extends SqlSessionDaoSupport implements StudentDao { public Student selectOne(long uid) {
final SqlSession session = this.getSqlSession();
String statement = "me.silentdoer.ssmdemo.pojo.StudentMapper.selectOne";
return session.selectOne(statement, uid);
} /*@Autowired // by type
@Qualifier("sqlSessionFactory")*/
@Resource // by name and default is setter rm set and lower first char
@Override
public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) {
super.setSqlSessionFactory(sqlSessionFactory);
}
}

3.service层的编码

package me.silentdoer.ssmdemo.service;

import me.silentdoer.ssmdemo.pojo.Student;

/**
* @author silentdoer
* @version 1.0
* @description the description
* @date 4/21/18 2:43 PM
*/
public interface StudentService {
// ERP Logic layer, like login process etc.
Student getOneUserWithLogic(Long uid);
}
package me.silentdoer.ssmdemo.service.impl;

import me.silentdoer.ssmdemo.dao.StudentDao;
import me.silentdoer.ssmdemo.pojo.Student;
import me.silentdoer.ssmdemo.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service; import javax.annotation.Resource; /**
* @author silentdoer
* @version 1.0
* @description the description
* @date 4/21/18 2:43 PM
*/
@Service("studentService") // need trans to studentService, otherwise will be studentServiceImpl will occur can not get bean by name
public class StudentServiceImpl implements StudentService {
// field name can diff with it's getter&setter; in structure is use getter&setter name.
private StudentDao studentDao; @Autowired
@Qualifier("studentDao")
public void setStudentDao(StudentDao studentDao) {
this.studentDao = studentDao;
} public Student getOneUserWithLogic(Long uid) {
// some logic impl
if(uid == null){
throw new IllegalArgumentException("uid is not null, please check.");
}
System.out.println(String.format("uid is:%s", uid));
Student student = this.studentDao.selectOne(uid);
return student;
}
}

4.action层的编码(controller)

package me.silentdoer.ssmdemo.action.index;

import com.opensymphony.xwork2.ActionSupport;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller; /**
* @author silentdoer
* @version 1.0
* @description the description
* @date 4/21/18 10:53 PM
*/
@Controller
public class IndexAction extends ActionSupport {
}
package me.silentdoer.ssmdemo.action.student;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import me.silentdoer.ssmdemo.pojo.Student;
import me.silentdoer.ssmdemo.service.StudentService;
import org.apache.struts2.interceptor.RequestAware;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller; import javax.annotation.Resource;
import java.util.Map; /**
* @author silentdoer
* @version 1.0
* @description the description
* @date 4/21/18 2:45 PM
*/
@Scope("prototype") // must be set prototype
@Controller("studentAction") // Or @Component for component-scan by annotation-filter
public class StudentAction extends ActionSupport /*implements RequestAware*/ {
private static final long serialVersionUID = 1L; // ActionSupport implements Serializable
private Long uid;
private Student student;
@Resource
private StudentService studentService; // like SpringMVC InternalResourceViewResolver to search success mapping file
@Override
public String execute(){
// setter for jsp usage, struts2 will purge the map to request attr when after execute().
Map request = (Map) ActionContext.getContext().get("request");
// request obj is generate&store by struts2, so request.put is also struts2 to put key-value to request attr.
request.put("requestAttrKey", "value8888888");
try {
Student student = this.studentService.getOneUserWithLogic(this.uid);
System.out.println(String.format("The student is: %s", student));
this.student = student;
}catch (Exception ex){
// to log exception
ex.printStackTrace();
request.put("error", ex.getMessage());
return ERROR; // error page
}
return SUCCESS; // normal page
} public void setStudentService(StudentService studentService) {
this.studentService = studentService;
} public void setUid(Long uid) {
this.uid = uid;
} // student will put to request attr, key is student
public Student getStudent() {
return student;
}
}

五:数据库和表的建立

数据库名为db_test,表名为student,里面就五个字段,可以参考pojo建立;

六:源码地址

github地址:https://github.com/Silentdoer/demos.git的Combine-Spring-Struts2-Mybatis项目

整合Spring+Struts2+Mybatis加spring单元测试等的更多相关文章

  1. 手动配置三大框架整合:Spring+Struts2+mybatis

    如今主流的项目框架中,数据库持久层有可能不是hibernate,而是mybatis或者ibatis,事实上它们都是一样的,以下我来把环境搭建一下: [导入相关jar包]新建web项目projectms ...

  2. Java基础-SSM之Spring和Mybatis以及Spring MVC整合案例

    Java基础-SSM之Spring和Mybatis以及Spring MVC整合案例 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 能看到这篇文章的小伙伴,详细你已经有一定的Java ...

  3. OSGI企业应用开发(十四)整合Spring、Mybatis、Spring MVC

    作为一个企业级的Web应用,MVC框架是必不可少的.Spring MVC目前使用也比较广泛,本文就来介绍一下如何在OSGI应用中实现Spring.Mybatis.Spring MVC框架的整合,其中S ...

  4. OSGI企业应用开发(十五)基于Spring、Mybatis、Spring MVC实现一个登录应用

    前面文章中,我们已经完成了OSGI应用中Spring.Mybatis.Spring MVC的整合,本篇文章我们就在这个基础上来完成一个简单的登录应用,其中用户名和密码需要从数据库中查询. 前面文章中, ...

  5. Spring+Struts2+Mybatis整合

    1. 创建项目 2. 添加Spring能力 使用MyEclipse自动加载Struts2和Spring的jar包和配置文件,并在web.xml文件中添加上下文和监听器 web.xml文件如下: < ...

  6. 搭建Spring + SpringMVC + Mybatis框架之三(整合Spring、Mybatis和Spring MVC)

    整合Spring和SpringMVC 之前已经整合了spring和mybatis,现在在此基础上整合SSM. 项目目录: 思路:SpringMVC的配置文件独立,然后在web.xml中配置整合. (1 ...

  7. 整合第二次(SSM第一次)------------>spring+struts2+mybatis

    今天我们来讲解一下SSM整合,感觉整合这个比上一篇整合更费时,原因在于自己不太熟悉MyBatis了,下午的时候恶补了一下,看了一下相关的文档和PDF电子书,知识真的是你不用就会忘记的,以后还是不能懈怠 ...

  8. 6、Spring+Struts2+MyBatis(mybatis有代理)整合增删改查

    1.创建如下的oracle脚本 create table userinfo (id ), name ), password telephone ), isadmin )); --4.2 用户表序列 c ...

  9. spring+struts2+mybatis

    struts2.2.3 + spring3.1.0 + mybatis3.1.0集成简单demo 项目下载地址:http://download.csdn.net/detail/afgasdg/4171 ...

随机推荐

  1. echarts中国地图散点涟漪效果

    echarts中国地图例子:http://gallery.echartsjs.com/editor.html?c=effectScatter-map 代码: var data = [{ name: ' ...

  2. iPhone X系列 的获取 - 安全区顶部和底部高度

    ///1. 获得当前窗口 var JY_WINDOW: UIWindow? { get{ if let app = UIApplication.shared.delegate as? AppDeleg ...

  3. c++ 中map 的find 函数用法

    Map中,find函数用来定位数据出现位置,当含有该数据,即查找成功时,返回数据所在未知的迭代器, 如果查找失败,则返回end()函数所在的迭代器,因此用是否等于end来判断是否查找成功. 程序示例: ...

  4. java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet解决

    spring配置之后启动报错,如下: java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServl ...

  5. 解决JFinal多文件上传时只获取到第一个文件名

    我的思路: 用户生成时随即生成一串随机字符作为该用户的文件上传目录,并保存该字符串到用户的某一字段.需要显示上传的附件时,遍历这个文件夹.上传时可把文件名设置为上传时间. 1.生成上传路径 可写在注册 ...

  6. JS高级:事件冒泡和事件捕获;

    1.事件:浏览器客户端上客户触发的行为成为时事件:所有的事件都是天生自带的,不需要我们去绑定,只需要我们去触发 当用户触发一个事件时,浏览器的所有详细信息都存在一个叫做event的对象上,我们把它叫做 ...

  7. c# Parallel.For 并行编程 执行顺序测试

    因为有个for 实际执行结果尽管是按照for里边的顺序执行,但处理器让哪个分线程先执行,谁先处理完就不一定了. 对于要求结果需要先后顺序的,比如对text内容的操作, 用并行 Parallel.For ...

  8. C# iframe session 丢失

    在页面A中使用iframe引用另一站点页面B,但页面B上面的session总是丢失,百度了一下,不用改程序,直接在iis里面操作,解决方法如下 1.打开IIS管理器 inetmgr 2.选择被嵌入if ...

  9. hdu 4717(三分) The Moving Points

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=4717 n个点,给出初始坐标和移动的速度和移动的方向,求在哪一时刻任意两点之间的距离的最大值的最小. 对于最 ...

  10. Eclipse的下载及安装

    Eclipse的下载地址: https://www.eclipse.org/downloads/ 下载完成后,双击安装包即可安装 选择 Eclipse IDE for Java EE Decelope ...