2018-10-23:示意图效果与AOP概念

示意图效果

jQuery

效果:鼠标进入示意图区域,在示意图中心显示提示内容

  1. 根据服务器返回的div设置的相关信息包括(宽,高,左偏移距离,上偏移距离和提示信息)。
  2. 示意图div为relative,提示div为absolute,将提示信息和编号等后续需要的内容,通过attr方法保存到追加的div中。
  3. 文字居中,由于存在其他设置,line-height无效,需要通过height(),width()方法获取提示div的大小,获取文字span的高度之后,进行计算后偏移文字span。
html:
css: script:
Ajax&Json&jQuery

开始步骤同效果1

Detail.java:
package entity;

public class Detail {
    /*宽*/
    private int width;
    /*高*/
    private int height;
    /*左偏移量*/
    private int left;
    /*上偏移量*/
    private int top;
    /*描述信息*/
    private String desc;
    
    public Detail() {
        super();
    }
    
    public Detail(int width, int height, int left, int top, String desc) {
        super();
        this.width = width;
        this.height = height;
        this.left = left;
        this.top = top;
        this.desc = desc;
    }

    public int getWidth() {
        return width;
    }
    public void setWidth(int width) {
        this.width = width;
    }
    public int getHeight() {
        return height;
    }
    public void setHeight(int height) {
        this.height = height;
    }
    public int getLeft() {
        return left;
    }
    public void setLeft(int left) {
        this.left = left;
    }
    public int getTop() {
        return top;
    }
    public void setTop(int top) {
        this.top = top;
    }
    public String getDesc() {
        return desc;
    }
    public void setDesc(String desc) {
        this.desc = desc;
    }
    
    
}

DetailAction.java:
package action;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;

import entity.Detail;
import net.sf.json.JSONArray;

public class DetailAction extends ActionSupport{

    private static final long serialVersionUID = 1L;

    public String getAllDetail() throws Exception{
        ServletActionContext.getResponse().setCharacterEncoding("utf-8");
        ServletActionContext.getRequest().setCharacterEncoding("utf-8");
        ServletActionContext.getResponse().setContentType("text/html; charset=utf-8");
     

        PrintWriter out = ServletActionContext.getResponse().getWriter();
        
        Detail detail1 = new Detail(66,196,54,60,"firstDiv");
        Detail detail2 = new Detail(160,110,180,38,"secondDiv");
        Detail detail3 = new Detail(160,88,200,226,"thirdDiv");
        List details = new ArrayList();
        details.add(detail1);
        details.add(detail2);
        details.add(detail3);
        
        JSONArray jsondetails = JSONArray.fromObject(details);
        out.print(jsondetails.toString());
        
        return null;
    }
}

示意图.html




Insert title here





    

3.公共显示内容div,定位为absolute,获取鼠标进入提示div时候的坐标,使用clientX获取的是相对于浏览器的偏移,所以还要减去父定位div的相对浏览器的偏移,可以使用position,offset等方法直接获取,但浏览器兼容性有区别,可以使用css('marginLeft')的方式获取并截取字符串后,和鼠标进入的偏移进行相减后对公共div进行偏移和内容显示。
如果需要div显示在鼠标停止的位置,需要另外获取坐标。


AOP面向切面的编程 一组有相似特征方法,特定时间点的附加业务逻辑编程

  • OOP的不足
    如添加到数据库记日志,修改数据记日志,特殊的ip访问记日志,会造成冗余代码,污染了核心业务逻辑。
  • 基本概念
    连接点(joinpoint)
    特定点,方法执行只有三个特定点,方法开始之前,方法结束之后(返回值),抛出异常
    切入点(pointcut)
    n个连接点的集合,按有相近或者相似方法名称的集合
    通知(advice)
    附加功能
    方案(advisor)

pointcut = joinpoint * n
advisor = advice + pointcut


ChildrenTest.java

package gxa.aop;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

public class ChildrenTest {
    private String handState = "很脏";
    
    public String getHandState() {
        return handState;
    }

    public void setHandState(String handState) {
        this.handState = handState;
    }

    public void eatFruit() {
        System.out.println("吃水果");
    }

    public void eatLunch() {
        System.out.println("吃水果");
    }

    public void eatSnacks() {
        System.out.println("吃零食");
    }

    public void playJoy() {
        System.out.println("玩玩具");
    }

    public static void main(String[] args) {
        //代理工厂
        ApplicationContext context = new 
                FileSystemXmlApplicationContext("src/applicationContextAop.xml");
        Children children = (Children)context.getBean("children");
        System.out.println("没洗手之前"+children.getHandState());
        children.eatFruit();


    }
}

WashHandAdvice.java

package gxa.aop;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

import org.springframework.aop.MethodBeforeAdvice;

public class WashHandAdvice implements MethodBeforeAdvice {

    @Override
    public void before(Method method, Object[] arg1, Object target) throws Throwable {
        System.out.println("洗手");   
        Field fd = target.getClass().getDeclaredField("handState"); 
        fd.setAccessible(true);
        fd.set(target,"很干净");
        System.out.println("吃东西之前"+((Children)target).getHandState());
    }

}

applicationContextAop.java



    
    
    
    
    
    
    
     
      .*eat.*
     
    
    
    
     
     
    
    
    
     
     
      
       beforeAdvisor
      
     
    



思考:商品类有标价和成交价格,设置各种活动(事前通知,打折,抵扣),获得实际的成交价格。

你可能感兴趣的:(2018-10-23:示意图效果与AOP概念)