广核电项目杂七杂八小结
1,shior过滤,xss过滤
2,serviceResult类型的返回
3,soa面向服务架构
4,对登陆的验证,url的验证,用户角色的验证使用shior
5,对Charsequement的理解,提供了length(),charat()等方法,String,StringBuilder,StringBuffer都是实现了charSequement接口。string类型的length方法是charSequement提供
6,java的nio,实现多路复用,实现异步的方式除了多线程外还有多进程的方式
Selector(选择器)是Java NIO中能够检测一到多个NIO通道,并能够知晓通道是否为诸如读写事件做好准备的组件。这样,一个单独的线程可以管理多个channel,从而管理多个网络连接。
Java NIO中的DatagramChannel是一个能收发UDP包的通道。因为UDP是无连接的网络协议,所以不能像其它通道那样读取和写入。它发送和接收的是数据包
Java NIO中的FileChannel是一个连接到文件的通道。可以通过文件通道读写文件。
FileChannel无法设置为非阻塞模式,它总是运行在阻塞模式下。
Channel,Buffer 和 Selector 构成了核心的API。
既可以从通道中读取数据,又可以写数据到通道。但流的读写通常是单向的。
通道可以异步地读写。
通道中的数据总是要先读到一个Buffer,或者总是要从一个Buffer中写入。
正如上面所说,从通道读取数据到缓冲区,从缓冲区写入数据到通道。
Java NIO中的Buffer用于和NIO通道进行交互。如你所知,数据是从通道读入缓冲区,从缓冲区写入到通道中的。
缓冲区本质上是一块可以写入数据,然后可以从中读取数据的内存。这块内存被包装成NIO Buffer对象,并提供了一组方法,用来方便的访问该块内存。http://ifeve.com/tag/nio/
seo:搜索引擎的优化http://www.chinaz.com/web/2011/0513/179907.shtml https://baike.baidu.com/item/搜索引擎优化/3132?fr=aladdin&fromid=102990&fromtitle=seo
表单校验https://www.cnblogs.com/linjiqin/p/3431835.html
控制文本框只能输入数字<td><input name=’company’ type=’text’ id=”company” class=’form-control w200′ onkeyup=”this.value=this.value.replace(/\D/g,”)” onafterpaste=”this.value=this.value.replace(/\D/g,”)”> <span></span></td>
另一种方式就是失去焦点时也能校验,避免粘贴复制,<td><input name=’company’ type=’text’ id=”company” class=’form-control w200′ onkeyup=”(this.v=function(){this.value=this.value.replace(/[^0-9-]+/,”);}).call(this)” onblur=”this.v();”>
<span></span></td>
任何一个表名字段都需要有相应的字段描述
CREATE TABLE `product_register` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`product_code` VARCHAR(50) DEFAULT NULL COMMENT ‘商品编号’,
`product_name` VARCHAR(30) DEFAULT NULL COMMENT ‘商品名称’,
`product_address` VARCHAR(50) DEFAULT NULL COMMENT ‘商品地址’,
`phone_number` INT(11) DEFAULT NULL COMMENT ‘手机号’,
`staff_id` VARCHAR(30) DEFAULT NULL COMMENT ‘员工编号’,
`staff_name` VARCHAR(20) DEFAULT NULL COMMENT ‘员工名称’,
`create_time` DATETIME DEFAULT NULL COMMENT ‘创建时间’,
`update_time` DATETIME DEFAULT NULL COMMENT ‘修改时间’,
PRIMARY KEY (`id`)
) COMMENT ‘商品登记’
ConstantsEJS
form-control,是bootstrap框架,表示为input添加一个表单控件
@RequestMapping(value=”/stock.html”,method={RequestMethod.GET})
数据库的读写分离
—–读的数据库:
<?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.sln.dao.shop.write.product.ProductRegisterWriteDao”>
<select id=”get” parameterType=”Integer” resultMap=”com.sln.entity.product.ProductRegister”>
select
<include refid=”selectColumn”/>
from `product_register`
where `id` = #{id}
</select>
<sql id=”selectColumn”>
`productCode`,
`productName`,
`productAddress`,
`phoneNumber`,
`staffId`,
`staffName`,
`createTime`
</sql>
</mapper>
—-写的数据库:
<?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.sln.dao.shop.write.product.ProductRegisterWriteDao”>
<resultMap id=”ProductRegisterResult” type=”com.sln.entity.product.ProductRegister”>
<result property=”id” column=”id” />
<result property=”productCode” column=”product_code” />
<result property=”productName” column=”product_name” />
<result property=”productAddress” column=”product_address” />
<result property=”phoneNumber” column=”phone_number” />
<result property=”staffId” column=”staff_id” />
<result property=”staffName” column=”staff_name” />
<result property=”createTime” column=”create_time” />
<result property=”updateTime” column=”update_time” />
</resultMap>
<select id=”get” parameterType=”Integer” resultMap=”ProductRegisterResult”>
select
<include refid=”selectColumn”/>
from `product_register`
where `id` = #{id}
</select>
<sql id=”selectColumn”>
`productCode`,
`productName`,
`productAddress`,
`phoneNumber`,
`staffId`,
`staffName`,
`createTime`
</sql>
<update id=”update” parameterType=”com.sln.entity.product.ProductRegister”>
update `product_register`
<set>
<if test=”id != null”>`id`= #{id},</if>
<if test=”productCode != null”>`product_code`= #{productCode},</if>
<if test=”productName != null”>`product_name`= #{productName},</if>
<if test=”productAddress != null”>`product_address`= #{productAddress},</if>
<if test=”phoneNumber != null”>`phone_number`= #{phoneNumber},</if>
<if test=”staffId != null”>`staff_id`= #{staffId},</if>
<if test=”staffName != null”>`staff_name`= #{staffName},</if>
<if test=”createTime != null”>`create_time`= #{createTime},</if>
<if test=”updateTime != null”>`update_time`= #{updateTime}</if>
</set>
where `id` = #{id}
</update>
<insert id=”insert” parameterType=”com.sln.entity.product.ProductRegister” useGeneratedKeys=”true” keyProperty=”id” keyColumn=”id”>
insert into
`product_register`
(
`product_code`,
`product_name`,
`product_address`,
`phone_number`,
`staff_id`,
`staff_name`,
`create_time`,
`update_time`
)
values
(
#{productCode},
#{productName},
#{productAddress},
#{phoneNumber},
#{staffId},
#{staffName},
#{createTime},
#{updateTime}
)
</insert>
</mapper>
mysql的读写分离:https://zhidao.baidu.com/question/362214720713060092.html
mysql的salve是一个半同步的机制?
easyui;表格初始化
<table id=”dataGrid” class=”easyui-datagrid”
data-options=”rownumbers:true
,singleSelect:true 设置为true就表示只允许选择一行
,autoRowHeight:false 定义设置行的高度,设置为false可以提高负载性能
,fitColumns:true
,toolbar:’#gridTools’
,striped:true
,pagination:true 设置为true就表示启用分页栏
,pageSize:’${pageSize}’
,fit:true
,url:’${currentBaseUrl}/registerlist’
,queryParams:queryParamsHandler()
,onLoadSuccess:dataGridLoadSuccess
,method:’get'”>
<thead>
会有一个数据字典,通过数据字典去加载状态,当处理下拉框的时候:
<p class=”p4 p-item”>
<label class=”lab-item”>处理结果 :</label>
<@cont.select id=”q_name” codeDiv=”PRODUCT_REGI_STAT” style=”width:80px”/>
</p>
首先是各个工程,其次是一个总工程,总的工程通过pom配置文件进行一个初始化的顺序,多个工程通过modules聚合,规则如下:
<?xml version=”1.0″ encoding=”UTF-8″?>
<project xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns=”http://maven.apache.org/POM/4.0.0″
xsi:schemaLocation=”http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd”>
<name>sln</name>
<url>http://maven.apache.org</url>
<modelVersion>4.0.0</modelVersion>
<groupId>com.sln</groupId>
<artifactId>sln</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>sln-parent</module>
<module>sln-core</module>
<module>sln-service</module>
<module>sln-service-impl</module>
<module>sln-front</module>
<module>sln-h5</module>
<module>sln-admin</module>
<module>sln-seller</module>
</modules>
<!– 项目发布 –>
<distributionManagement>
<repository>
<id>nexus-releases</id>
<name>Nexus Release Repository</name>
<url>http://114.119.7.147:8081/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<name>Nexus Snapshot Repository</name>
<url>http://114.119.7.147:8081/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
</project>
Nexus Release Repository私服,这样一来就减少了对远程的依赖,同时减少了带宽,加速了项目的一个构建过程。Nexus Release Repository会先从远程的中央服务器下载资源,而maven本地仓库通过http的setting.xml和pom.xml就直接从私服里下载就可以了
nexus-snapshots设置权限
sessionid的产生https://www.cnblogs.com/woshimrf/p/5317776.html
fastjson(阿里巴巴的json转换)
表单验证,首先导入validform的插件到resource下,给form表单一个id,然后写一个script标本,根据表单id初始化表单验证,回掉调函数可有可没有,验证通过就会调用回调函数,制定datatype.导入validform的min.js文件
导入validform的js—>
<script type=”text/javascript” src=’${(domainUrlUtil.SLN_STATIC_RESOURCES)!}/Validform_v5.3.2/demo/js/Validform_v5.3.2_min.js’></script>
初始化验证表单—>
<script type=”text/javascript”>
$(function(){
$(“#form-company-info”).Validform({
btnSubmit:”.btn_sub”,
btnReset:”.btn_reset”,
tiptype:2,
callback:function(form){
submitFrom(form,”${(domainUrlUtil.SLN_URL_RESOURCES)!}/product/create.html”);
return false;
}
});
})
</script>
表单内置校验—>
避免主从库数据同步延迟所有退货表的数据从写库读取
需要注意的是使用easyui插件的时候需要注意,在进行编辑的时候要注意,不同数据类型的回显是不一样的,有日期框,校验框,其中在进行日期框回显时需要引入一个WdatePicker.js文件,然后将datetimebox中的datetime类型转为string类型,然后再转为需要的类型,示例如下:
<script type=”text/javascript” src=”${domainUrlUtil.SLN_STATIC_RESOURCES}/resources/admin/jslib/My97DatePicker/WdatePicker.js”></script>
<div class=”fluidbox”>
<p class=”p6 p-item”>
<label class=”lab-item”>手机号码: </label>
<input type=”text” id=”phoneNumber” name=”phoneNumber” value=”${(ProductRegister.phoneNumber)!”}” class=”txt w200 easyui-numberbox”/>
</p>
<p class=”p6 p-item”>
<label class=”lab-item”>创建时间: </label>
<input type=”text” id=”createTime” name=”createTime” value=”${(ProductRegister.createTime?string(‘yyyy-MM-dd HH:mm:ss’))!”}” class=”txt w200 easyui-validatebox” required
onclick=”WdatePicker({dateFmt:’yyyy-MM-dd HH:mm:ss’,minDate:’#F{$dp.$D(\’createTime\’)}’});” />
</p>
</div>
注意,对于数字类型的需使用number框,日期类型使用datetimebox框,以及easyui-validatebox框
注意,对于easyui框架的文本域这一块,尽量不使用easyui框架提供的textbox,textbox无法换行,只能一行输入,此时使用testarea文本域,示例如下:
<textarea name=”retroactionReason” id=”retroactionReason” style=”width:300px;height:120px”></textarea>
数据字典,数据库状态的转化,前台显示的时中文,而不是数字的化,需要格式化,步骤有三个,如下:
第一步:
<#noescape>
codeBox = eval(‘(${initJSCodeContainer(“PRODUCT_REGI_STAT”)})’);
</#noescape>
第二步:
function typeFormat(value,row,index){
return codeBox[“PRODUCT_REGI_STAT”][value];
}
第三步:
<th field=”productRegiStat” width=”120″ align=”center” formatter=”typeFormat”>处理结果</th>
这样下来就行了
页面上如果要显示时间的话,有可能需要注意显示的时间类型时datetime还是date还是time类型,ftl文件中显示时间的话,步骤有两步
一是引入<script type=”text/javascript” src=”${domainUrlUtil.SLN_STATIC_RESOURCES}/resources/front/js/My97DatePicker/WdatePicker.js”></script>
二是指定显示的格式${(productRegi.createTime?string(‘yyyy-MM-dd HH:mm:ss’))!”}
jquery.validate.min.js,表单的校验使用,三个步骤,一是:引入js,即<script type=”text/javascript” src=’${(domainUrlUtil.SLN_STATIC_RESOURCES)!}/js/jquery.validate.min.js’></script>
二是:声明全局的事件:
<script type=”text/javascript”>
$().ready(function() {
$(“#forminfo”).validate({
submitHandler:function(form){
alert(“恭喜你,缺货商品登记成功!”);
form.submit();
}
});
});
$(function(){
$(“#productCode”).blur(function(){
if(this.value==”){
$(“#code”).html(“<font color=’red’>商品编号不能为空</font>”);
}else{
$(“#code”).html(“”);
}
});
…….
});
</script>
三:是在相应的字段中的class样式中添加required,样式是可以起到叠加的效果的<input name=’productCode’ type=’text’ id=”productCode” class=”form-control w200 required” value=”” >
如此就好了
选中列表中的列,判断该列的状态,通过:
if(selectedCode.productRegiStat == 3){
$.messager.alert(‘提示’,’只有[未打回]的记录才可以打回。’);
return;
}
和:
<th field=”productRegiStat” width=”120″ align=”center” formatter=”typeFormat”>处理结果</th>
jenkins?
C:\Users\slooong-psm\AppData\Local\Packages\Microsoft.MicrosoftEdge_8wekyb3d8bbwe\TempState\Downloads(课程表插件)
Parameter ‘kindType’ not found. Available parameters are [param1, modelmap],出现这样的情况是因为没有在xml文件中指定是那个属性,因该是#{modelmap.param1},这里的modelmap应该和model层@param(“model”)中的model一致
jquery-validate.js的验证插件:http://www.runoob.com/jquery/jquery-plugin-validate.html
jquery-validate.js校验过程是有一些,像内置的校验例如required:true 或者是number:”必须是数字”,这些提示都是会默认触发label for标签,其中for属性和要绑定的id的文本框中id属性一致,默认情况下该属性是隐藏的,只有触发的时候才会显示,generated=”true” ,当然如果不想拓展方法的话也可以自定义一个事件,也不要忘了给class样式添加error样式示例如下:
第一步:<div class=”col-md-3″>
<input type=”text” class=”form-control” id=”OrderCountWarn” name=”OrderCountWarn” onblur=”myValidate()”>
<label for=”OrderCountWarn” generated=”true” style=”display: none;” id=”panduan” class=”error”>后者不能大于前者</label>
</div>
第二步:function myValidate(){
var orderCountTip=$(“#OrderCountTip”).val();
var orderCountWarn=$(“#OrderCountWarn”).val();
if(orderCountWarn>=orderCountTip){
document.getElementById(“panduan”).style.display = “block”;
}
如此两步就可以了
resource:99 Uncaught SyntaxError: Unexpected string,出现这样问题要么就是少了引号,要么就是括号多或少了
easui校验之自定义校验:
校验一个的:
<p class=”p3 p-item”>
<input type=”text” id=”ComprehensiveMarkWarn” name=”ComprehensiveMarkWarn”
class=”txt w200 easyui-numberbox” missingMessage=”请输入相应的警告值” data-options=”required:true” validType=”comparewith[‘ComprehensiveMarkTip’]” />
校验多个的:
<p class=”p3 p-item”>
<input type=”text” id=”ComprehensiveMarkEliminate” name=”ComprehensiveMarkEliminate”
class=”txt w200 easyui-numberbox” missingMessage=”请输入相应的淘汰值” data-options=”required:true,validType:[‘rangvalue’,’comparewith[ComprehensiveMarkWarn]’]” />
</p>
</p>
相对应js:
comparewith: {
validator: function (value, param) {
if ($(“#” + param[0]).val() != “” && value != “”) {
return $(“#” + param[0]).val()>value;
} else {
return true;
}
},
message: ‘后者不能大于前者!’
},
rangvalue: {//限制输入范围是0-5
validator: function (value) {
return /^[0-5]$/i.test(value);
},
message: ‘请输入0-5之间的数字!’
},
jquery.1.9.js为了安全起见,使用parseHTML进行转换:
<p class=”p3 p-item”>
<input type=”text” id=”ComprehensiveMarkEliminate” name=”ComprehensiveMarkEliminate”
class=”txt w200 easyui-numberbox” missingMessage=”请输入相应的淘汰值” data-options=”required:true,validType:[‘rangvalue’,’comparewith[$.parseHTML(ComprehensiveMarkWarn,document, true)]’]” />
</p>
注意,如果是多个单引号或者多个双引号,要注意是否需要转义,单引号只能嵌套双引号,双引号只能嵌套单引号,如果出现这种类似的错误 Syntax error, unrecognized expression: ,除了看是否多或者少了符号,还要考虑是否需要转义。
<p class=”p3 p-item”>
<input type=”text” id=”ComprehensiveMarkWarn” name=”ComprehensiveMarkWarn”
class=”txt w200 easyui-numberbox” missingMessage=”请输入相应的警告值”
data-options=”required:true,validType:[‘rangvalue’,’comparewith[\’ComprehensiveMarkTip\’]’]” />
</p>
对于如果需要对状态进行字体颜色的判断,如果是通过return返回的话,可以是通过字符串的拼接来完成,示例如下:
function typeState(value,row,index){
if(value==3){
return ‘<font color=”red”>’+codeBox[“BUSINESS_STATE”][value]+'</font>’;
}
return codeBox[“BUSINESS_STATE”][value];
}
在进行批量插入的时候要注意以下几点:
主键一定要自增长,不然就会出现没插入进数据,但是也没报错的原因
然后model里对于集合参数,一定要给定@param(“list”)
在xml文件中paratermType类型是:java.util.List
批量插入模板:
<insert id=”insertSellerEliminate” parameterType=”java.util.List”>
insert into seller_eliminate (kind_type,tip_value,warn_value,eliminate_value,create_time)
values
<foreach collection=”list” item=”item” index=”index” separator=”,” >
(#{item.kindType},#{item.tipValue},#{item.warnValue},#{item.eliminateValue},now())
</foreach>
</insert>
注意,批量更新的时候一定要有主键id,没有主键id的话是没法更新的,示例如下:
<!–updateBatch批量更新 –>
<update id=”updateBatch” parameterType=”java.util.List”>
<foreach collection=”list” item=”item” index=”index” separator=”;”>
update seller_eliminate set tip_value = #{item.tipValue} , warn_value = #{item.warnValue} , eliminate_value = #{item.eliminateValue}, update_time=now() WHERE id = # {item.id}
</foreach>
</update>
对于需要指定的格式的化,可以这样处理,用到了BigDecimal 和DecimalFormat
Double scoreService = Double.parseDouble(seller.getScoreService());
Double scoreDeliverGoods = Double.parseDouble(seller.getScoreDeliverGoods());
Double scoreDescription =Double.parseDouble(seller.getScoreDescription());
Double avg=(scoreService+scoreDeliverGoods+scoreDescription)/3;
BigDecimal bg = new BigDecimal(avg);
double f1 = bg.setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();//1表示保留小数点后一位
DecimalFormat format = new DecimalFormat(“0.0”);//表示保留的格式是这样的格式
String sMoney = format.format(f1);
seller.setScoreService(sMoney);