页面常用整理

常用的知识点:

json格式转换:
日期格式化
        JsonConfig  config=new JsonConfig();
        config.registerJsonValueProcessor(Date.class, new JsonDate());
JSONObject  json=JSONObject.fromObject(pojo,config);
    json对象
        JSONObject  json=JSONObject.fromObject(pojo);
    json数组、集合:
        JSONArray arr=JSONArray.fromObject(object);
输入框不可编辑:
  方法1: onfocus=this.blur() 当鼠标放不上就离开焦点
    <input type="text" name="input1" value="中国" onfocus=this.blur()>
  方法2:readonly
    <input type="text" name="input1" value="中国" readonly>
    <input type="text" name="input1" value="中国" readonly="true">
  方法3: disabled
    <input type="text" name="input1" value="中国" disabled="true">
A标签禁止跳转,执行javascript的方法
        href="javascript:document.getElementById(‘fm’).submit() " 
数据库备注:
  select table_name from user_tables; //当前用户拥有的表      
  select table_name from all_tables; //所有用户的表 
  select table_name from dba_tables; //包括系统表
  select table_name from dba_tables where owner='用户名'
  comment on column TableName.ColumnName is ‘备注名’;//为列添加备注
  comment on table TableName is '备注名';//为表添加备注
  select * from user_tab_comments//获取表的备注
  select * from user_col_comments//获取列的备注
  alter table student rename column classessId to classId  //修改列名
创建临时表数据:
  create table 临时表名 as insert into 临时表名 select * from 表名 where id=1;commit;
数据库视图权限:grant create view to baiyun
备份表数据: create table 备份表表名  as select * from 表名
还原表数据:insert into 备份表表名  select * from 表名
创建视图:create or replace view  视图名  as 
   Create     or    replace    view     sss    as    select c.classId,c.className,c.marjorId,m.marjorName from student t,marjor m,classes c where  c.marjorId=m.marjorId







元素不显示:
    Display: 设置元素显示或隐藏,隐藏不占据空间位置
    none不显示;
    block 以块级方式显示;
    inline 以行级方式显示;
    inline-block行块级显示,可以调整宽高,前后不换行
    visibility:visible显示,hidden不显示,隐藏时占据空间位置
      hidden:直接写就行,在xhtml中赋值为hidden
伪类样式:出现顺序固定,可以省略,只能出现在内部和外部,不能出现在行内
    a:link{ }默认
    a:hover{ }悬浮
    a:active{ }点击时
    a:visited{ }点击后
    书写顺序:L、V、H、A
    其他标签:默认用div、悬浮用div:
弹出消息框的方式
  输入:
    prompt(弹框的消息,输入框的默认值)
    返回用户输入在输入框中的内容
    返回的是字符串类型,转型要用到parseInt()、parseDouble()
  输出:
    alert(弹框的消息信息); 无返回值  
    confirm(弹框的消息信息);返回boolean值
禁用提交按钮:
      禁用:document.getElementById(“sub”).setAttribute(“disabled”,”disabled”);
      启用:document.getElementById(“sub”).removeAttribute(“disabled”);
      被禁用的按钮即不可用又不可点击
日期格式转换:
  Java中利用Object方式为日期赋值
  将字符串类型转为java的日期类型,然后转换为sql的日期类型
    new java.sql.Date(DateFormat.getDateInstance().parse(joinDate).getTime()))
    util.Dtae是sql.Date的父类
    util.Dtae转为sql.Date:
    new Date(da.getTime());
  将字符串转为Java的Date类型:
      DateFormat.getDateInstance().parse(String)
    new SimpleDateFormat("yyyy-MM-dd").parse(time);
  将日期转换为字符串
    new SimpleDateFormat("yyyy-MM-dd").format(date);
 Java中取得当前项目的根目录:
    TestPath.class.getResoure(“/template.html”).getPath();
    TestPath.class.getResoure(“/template.html”).getFile();

json常用:
   根据class取得多个对象,并取得他们的值:
        $('.mycount').each(function(){ arr.push(parseInt($(this).val())); });
    标签显示内容设值:
      .text(value);
        .html(value);
  表单value设值:
        .val(value);
  移除一行数据:
        $(this).parents('tr').remove();
  复选框是否被选中
        .is(':checked')
  复选框设值,是否被选中
        .attr('checked',’true’);
        .removeAttr("checked");
  循环遍历
      $.each(数组,事件(下标,对象));
      $.each(对象,事件(键,值));
      $.each(数组对象,事件(下标,对象));
DOM节点操作:
  在选择器的里面的最后面添加标签内容
     选择器.append(“标签内容”);   
        <p>Hello</p>
       $(“p”).append(“<h1>你好</h1>”);  
       结果:  <p>Hello <h1>你好</h1> </p>
  在选择器的里面的最前面添加 标签内容
     选择器.prepend(“内容”)  
      <p>Hello</p>
       $(“p”).prepend(“<h1>你好</h1>”);  
       结果:  <p><h1>你好</h1>Hello  </p>
  把选择器元素全部删除
       选择器.remove();                
       <p>Hello, <span>Person</span> <a href="#">and person</a></p>
       $(“p”).remove();
  把选择器元素里面的内容删除
      选择器.empty();                
    <p>Hello, <span>Person</span> <a href="#">and person</a></p>
     $(“p”).empty();  -->  <p></p>
  复选框:
    取得值  
        $("input[type='checkbox']").prop("checked");
    设定值
        $("input[type='checkbox']").prop("checked",true/false);

Jquery 使用ajax最完整写法
     $.ajax({
         type:”get/post”,
         url:”请求地址”,
         data:{“userName”: “wy” ,  “password”:”111”}  //post用的
         async:true/false,      是否异步
         cache:true/false,      是否缓存页面,false url?r=Math.random()
         dataType:”text/html/script/xml/json/jsonp”,  返回类型
         success:function( 变量名 ){
                解析
         },error:function(e){
              //出错操作
         }
     });

Jquery 使用ajax简洁写法,方便更多人用,精简
     $.get(url ,{参数名:值 ,参数名:值 },function(变量名){
            解析
     });

    $.post(url ,{参数名:值 ,参数名:值 },function(变量名){
            解析
     });
读取jdbc.properties中的变量值:
        Properties prop = new Properties();
     prop.load(BaseDao.class.getResourceAsStream("/jdbc.properties"));
     DRIVER = prop.getProperty("jdbc.driver");
      URL = prop.getProperty("jdbc.url");
    USERNAME = prop.getProperty("jdbc.username");
    PASSWORD = prop.getProperty("jdbc.password");
Bom对象内容:
    History:代表浏览器的访问历史, window.history.go(); 
        Go():0 代表刷新本页;1 去下一页;-1 返回上一页
        Back():返回前一个页面
        Forword():前进到历史进入过的下一个页面
    Location:代表浏览器的浏览地址 url ,window.location.href=’连接的地址’
        Href():跳转到一个页面
        Reload():重新载入当前页面,刷新
    Document:是用于查找和动态控制页面中标签元素的模型
        Referrer:返回前一个跳转页面的url
        url:返回当前文档的url



实例化对象方法:
    New student();
    Student.class.newInstance();
    Class.forName(“com.wize.studnet”).newInstance();
get提交乱码问题:
   1把servlet请求的参数取出来,转换成为ISO-8859-1,然后再转换成UTF-8
         String n=new String(name.getBytes("ISO-8859-1"), "UTF-8"); 
   2修改 tomcat/conf/server.xml 中的  <Connector>
      <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8" />
   3自定义filter对get请求的参数进行转码(先以iso-8895-1进行解码,然后再以utf-8进行编码)
Jsp页面日期格式:
    <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
    <fmt:formatDate value='${cost.CStardate}' pattern='yyyy-MM-dd' />
jsp页面取参数:
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
页面转发:
    request.getRequestDispatcher("index.jsp").forward(request,response);
重定向传参:
    response.sendRedirect("index.jsp")?id=<%=d.getDeptId()%>&name=<%= d.getDeptName()%>
    MyBaties的多表连接查询返回对象:
<resultMap type="com.wisezone.entity.Classes" id="classesType">
        <!-- 主键 -->
        <id property="classesId" column="classesid" />
        <result property="classesName" column="classesName" />
        <result property="startTime" column="startTime" />
        <result property="endTime" column="endTime" />
        <result property="numberCount" column="numberCount" />
        <!-- 多对一 -->
        <association property="major" javaType="com.wisezone.entity.Major">
            <id property="majorId" column="majorId" />
            <result property="majorName" column="majorName" />
        </association>
</resultMap>
使用:
    <select id="findById" parameterType="int" resultMap="classesType">





Oracle数据库利用myBaties框架,查询分页时<符号用&lt;
  方法一:
    &lt;<小于号                                           
    &gt; >大于号
    &amp;&和
    &apos;’单引号
    &quot;"双引号
方法二:
    用<![CDATA[ ]]>进行说明
    <![CDATA[ when min(starttime)<='12:00' and max(endtime)<='12:00']]>  
    MyBaties单独用时重要使用部分:
    SqlSessionFactory  sessionFactory=null;
    InputStream in=MyBtaisUtil.class.getResourceAsStream("/mybatis-config.xml");
    sessionFactory=new SqlSessionFactoryBuilder().build(in);
    SqlSession session = MyBtaisUtil.openSession();
    AssessmentMapper mapper = session.getMapper(AssessmentMapper.class);    
    session.commit();     session.rollback(); 复选框状态保持:     
<select id="marjorId" name="marjorId" class="form-control">       <option value="0">请选择</option>        <c:forEach items="${marjorArr}" var="s">    <option    <c:if test="${s.marjorId==param.marjorId}">selected</c:if>    value="${s.marjorId}">${s.marjorName}</option>      </c:forEach>     </select> 页面选择标签:    <c:choose>      <c:when test="${s.sex==0 }">男</c:when>      <c:when test="${s.sex==1 }">女</c:when>    </c:choose> javascript特别函数:    eval(“String”) //执行字符串     document.write(eval("2+2")) //输出4 Spring MVC注入:     @DateTimeFormat(pattern="yyyy-MM-dd") //实体类日期属性前     @Service //业务实现层逻辑层     @Controller // servlet注入标志     @Scope(value = "prototype") //每次都要实例化对象     @RequestMapping(value = "/admin/classes") //虚拟路径映射     @Autowired//自动注入,放在servlet属性前     @Resource(name = "classesServiceImpl") //自动注入值、     @ResponseBody //输出JSON对象标志     @PathVariable //将url传过来的参数,取出来赋值到后面的变量,在方法的()中 @WebServlet(value=” /admin/classes”) //html5的web虚拟路径映射 文件上传关键字:     <form enctype="multipart/form-data">      <input type="file" name="attach" id="attach" />     </form>     MultipartFile attach //方法的()中     attach.getInputStream() ; //获得输入流     <!-- 文件上传解析器 -->     <!-- 文件上传解析器 -->     <bean id="multipartResolver" class="org.springframework.web.multipart.         commons.CommonsMultipartResolver">       <!-- 设置上传文件最大尺寸,单位为B 5MB-->        <property name="maxUploadSize" value="5242880" />     </bean> 如果传过来的值为空,判断:     <c:if test="${empty s.portrait }"></c:if> //为空     <c:if test="${not empty s.portrait }"></c:if> //不为空 数据库回滚: throw new RuntimeException("批量上传学生信息失败的");   js中取出页面request中的参数:     1)       var a = '<%=request.getAttribute("aaa");%>' ;     2)       <input type="hidden" value="<%=request.getAttribute("aaa");%>" id="aaa"/>   var a = document.getElementById('aaa').value ; 3)  <input type="hidden" value="${student.name}" id="stuName"/>  var stuName = $('stuName').value ;// prototype.js新功能,简写. hibernate注入: 实体类     (1)这个表示一个实体类,Table表示对应数据库中的表名。       @Entity       @Table(name="t_emp")     (2)这个表示主键自动增长        mysql数据库           @Id           @GeneratedValue        oracle数据库           @Id           @SequenceGenerator(name = "FLINKSEQ", sequenceName = "flink_seq", initialValue = 1, allocationSize = 1)           @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "FLINKSEQ")     (3)这个表示关联对象以及关联的字段名字         @ManyToOne         @JoinColumn(name="dept_id")     (4)和数据库中字段不一样的,要通过这个属性写清楚。         @Column(name="emai")     (5)表示时间字段         @Temporal(TemporalType.TIMESTAMP)         和@Temporal(TemporalType.DATE) Dao.impl包中:    @Repository实体类数据访问层实现,放在类上 Service.impl包中:   @Service实体类业务逻辑层实现,放在类上        @Resource(name="flinkTypeDaoImpl")属性注入值放在setter方法上 Controller包中:       @Controller 是servlet标志,放在类上       @Scope(value="prototype") 每次实例化,放在类上       @Resource(name="flinkTypeServiceImpl")赋值,属性的setter方法上 测试类:放测试类上       @ContextConfiguration(locations="classpath:applicationContext.xml")       @RunWith(value=SpringJUnit4ClassRunner.class) struts传参:     getter方法     ActionContext.getContext().getContextMap().put("arrLinks", arrLinks); struts页面取值:     #r.id     id 利用反射取得泛型的类:     public abstract class CommonDaoImpl<T,PK extends Serializable> implements CommonDao<T, PK>{      @Autowired      private SessionFactory sessionFactory;      @Autowired      protected CommonSearchDao commonSearchDao;      private Class<T> entity;     public CommonDaoImpl(){ //取得T的实体类      Type type=this.getClass().getGenericSuperclass();      if( type instanceof ParameterizedType){       Type[] te=((ParameterizedType)type).getActualTypeArguments();      entity=(Class<T>) te[0];       }     }     @Override      public T findById(PK primaryKey) {     Object obj=sessionFactory.getCurrentSession().get(entity, primaryKey);      return (T)obj;     }     }

jsp页面代码的提取:

  对于一段的连续的页面代码会被重复用到,将js和css分别提取到单独的jsp文件
  在原页面通过<jsp:include page="common/common_js.jsp"></jsp:include>引用

 

转载于:https://www.cnblogs.com/by-1642146903/p/7107205.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值