冲冲冲冲冲

1、冲冲冲
目录

1、冲冲冲

在IDEA中 使用

 2、Decimal的计算(合同金额精度缺失,可以采用 bigdecimal )

 3、模板设计模式

4、Try{}catch(Exception e){} (图片失败房间租凭合同和客户身份证上传失败 可以使用重试机制)

5、事务(租房合同保存失败,数据不完整 进行业务规则校验和使用事务)

6、跨域(前后端分离 cookie 跨域,页面跨域,后台配置 cors )

7、内存溢出

7、 部署 

 八、Redis实现重复提交

Redis实现重复提交 

九、本地数据的持久化

十、生成pdf(合同预览,pdf,word 预览或者生成 pdf,下载查看 )

 十一、前端身份证校验

 

)1、运行在数据库中,会生成存储过程

drop PROCEDURE if EXISTS getSequence;
drop TABLE if EXISTS tb_sequence;
create PROCEDURE getSequence(in nus BIGINT)
begin
   DECLARE seqid BIGINT DEFAULT 0; 
 DECLARE datet VARCHAR(50) DEFAULT '';
 create table if not EXISTS tb_sequence(
    `id` bigint(20) NOT NULL,
      `name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
      `sequence` bigint(20) NOT NULL DEFAULT 0,
      PRIMARY KEY (`id`, `sequence`) USING BTREE
 );
 select sequence into seqid from tb_sequence where name='sequencename';
 if seqid=0 then
 insert into tb_sequence(id,name,sequence)values(1,'sequencename',0);
 end if;
 update tb_sequence set sequence=sequence+1 where name='sequencename';
   select sequence into seqid from tb_sequence where name='sequencename';
 select date_format(now(),'%Y%m%d%H%i%S') INTO datet;
 if nus=1 then
   select CONCAT(datet,'-',seqid) as seqnum;
 else
   select CONCAT(datet,'',seqid) as seqnum;
 end if; 
END;
在IDEA中 使用
)2、编写Mapper层 

@Mapper
@Repository
public interface XXXMapper{
    
    public String getSequence(Integer num);
}
 )3、编写XXX.xml

 

<select id="" paramentType="Integer" resultType="String">
    
    call getSequence(#{num})
 
</select>
)4、测试方法

String sequence = XXXMapper.getSequence(参数0);
String sequence = XXXMapper.getSequence(参数1);
 

 2、Decimal的计算(合同金额精度缺失,可以采用 bigdecimal )
)1、给数据库中decimal赋值

Good g = new Good();
 
g.setPrice(new BigDecimal("0.022222"));
)2、保存两位小数

BigDecimal b1 = new BigDecimal("0.1111");
 
BigDecimal a = b1.setScale(2,RoundingMode.HALF_UP); //向上取整
 )3、加减乘除运算

// 1、加
    
    BigDecimal b1 = new BigDecimal("0.11111");
    
    BigDecimal b2 = new BigDecimal("0.22222");
 
    b2.add(b1);
 
 
// 2、减
    BigDecimal b1 = new BigDecimal("0.11111");
    
    BigDecimal b2 = new BigDecimal("0.22222");
 
    b2.subtract(b1);
 
 
// 3、乘
 
    BigDecimal b1 = new BigDecimal("0.11111");
    
    BigDecimal b2 = new BigDecimal("0.22222");
 
    b2.multiply(b1);
 
// 4、除
 
    BigDecimal b1 = new BigDecimal("0.11111");
    
    BigDecimal b2 = new BigDecimal("0.22222");
 
    b2.subtract(b1);
)4、以%形式展示

    BigDecimal b1 = new BigDecimal("0.11111");
    
    NumberFormat number = NumberFormat.getPercentInstance();
    
    number.setMaximumFractionDigits(2);
 
    String format = number.format(b1);
 3、模板设计模式
)1、定义一个抽象类

public abstract class MoBanClass{
 
    
        public void maiche(String name,String num){
 
                    //选车
                    xuanche(name);
                       //选牌
                       xuanpai(num);
            }
    
        //选车
        public abstract void xuanche(String name);
        
        //选牌
        public abstract void xuanpai(String num);
 
 
}
 

 )2-1、定义两个类继承抽象类---类1

//隔壁老王继承了模板类
public class LaoWang extends MoBanClass{
 
 
        
        @Override
        public void xuanche(String name){
 
               System.out.println("隔壁老王买了新车"+name);
        }
 
         @Override
        public void xuanche(String num){
 
               System.out.println("隔壁老王选了车牌号"+num);
        }
 
 
 
}
)2-2、定义两个实体类继承抽象类 --- 类2

//隔壁老李继承了模板类
public class LaoWang extends MoBanClass{
 
 
        
        @Override
        public void xuanche(String name){
 
               System.out.println("隔壁老李买了新车"+name);
        }
 
         @Override
        public void xuanche(String num){
 
               System.out.println("隔壁老李选了车牌号"+num);
        }
 
 
 
}
)2-3、定义一个service层 为其赋值

public void MoBanlx(MoBanClass moBanClass){
 
    moBanClass.maiche("奔驰","88888");
}
@Test
public void t1(){
 
    goodService.MoBanlx(new Wang());
}
 
 
 
运行结果:
        隔壁老王买了新车奔驰
        牌照为88888
@Test
public void t1(){
 
    goodService.MoBanlx(new li());
}
 
 
 
运行结果:
        隔壁老李买了新车奔驰
        牌照为88888
4、Try{}catch(Exception e){} (图片失败房间租凭合同和客户身份证上传失败 可以使用重试机制)
try{
 
    //成功的时候正常返回ResultResponse
}catch(Exception e){
 
    //1、失败的时候返回一个失败的ResultResponse,根据返回信息,弹出提示框
 
    ResultResponse. resultResponse = new ResultResponse()
            .setCode(ResultResponse.SUCCESS.getCode())
            .setMsg(ResultResponse.SUCCESS.getMsg());
 
            return resultResponse;
    //2、返回一个让错误
}
5、事务(租房合同保存失败,数据不完整 进行业务规则校验和使用事务)
在add方法上添加注解  @Transactional(rollbackFor = Exception.class) 

6、跨域(前后端分离 cookie 跨域,页面跨域,后台配置 cors )
)1、前端cookie跨域

import vueCookies from 'vue-cookies'
Vue.use(vueCookies)
//配置允许前端操作Cookie
axios.defaults.withCredentials=true
)2、后台跨域

@Override
public void addCorsMappings(CorsRegistry registry) {
 
    registry.addMapping("/**")
            .allowedHeaders("*")
            .allowedMethods("*")
            .allowedOrigins("http://localhost:8080")
            .allowCredentials(true)
            .maxAge(3600*10);
}
 

)3、前端配置跨域  如果没有config  在项目目录下 创建vue.config.js

module.exports = {
    // pabulicPath:process.env.NODE_ENV === 'production' ? '' : '',
    devServer: {
        proxy: {
            '/api': {   //  拦截以 /api 开头的接口
                target: 'http://localhost:1127',//设置你调用的接口域名和端口号 别忘了加http
                changeOrigin: true,    //这里true表示实现跨域
                secure: false, // 如果是https接口,需要配置这个参数
                pathRewrite: {
                    '^/api': '/'  //这里理解成用‘/api’代替target里面的地址,后面组件中我们掉接口时直接用api代替 比如我要调用'http://40.00.100.100:3002/api/user/add',直接写‘/api/user/add’即可
                }
            },
        }
    }
}
)4、后端处理静态图片 

 
    1、加入@Configuration注解
    2、implements WebMvcConfigurer    
 
    3、重写方法
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/img/**").addResourceLocations("file:F:/img/");
    }
 

7、内存溢出
)1、-Xmx   256m 最大值  -Xms  256m 初始化堆内存 –Xmn 年轻代的大小 64m(如果怕出问题可以设置大一点,例如:128)  老年代不用设置 

 

7、 部署 
 )1-1、前端部署

 

1、打包生成dist
 npm run build
2、找到自己的nginx
编写config文件
server{
    
    listen 90;
    server_name localhost;
 
    location / {       
        root D:\\projectidea\\yuekao-ui\\dist;       
    }     
}
 
#:root是自己打包的dist文件的全路径
)1-2、后端部署

1、导入pom依赖
 
 <build>
        <plugins>
            <!--SpringBoot打包-->
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <finalName>lxp</finalName><!--打包成的name-->
                    <outputDirectory>E:/jar</outputDirectory><!--打包放好的位置-->
                    <mainClass>com.lin.Day02Test01Application</mainClass><!--启动类-->
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.6</version>
            </plugin>
        </plugins>
 
 
2、启动类继承SPringBootSpringBootServletInitializer
3、重写Configuer  返回.sources(this.getClass())
4、进入到jar包所在地,然后java -jar xxx.jar即可
 八、Redis实现重复提交
Redis实现重复提交 
)1、后端的处理

 

 @RequestMapping("/addMenu")
    public Integer addMenu(@RequestBody Map<String,String> map){
 
        1、获取名称
        String menuName = map.get("menuName");
        ValueOperations<String, String> ops = redisTemplate.opsForValue();
        2、如果存着就不加入
        Boolean aBoolean = ops.setIfAbsent(menuName, "");
        3、设置过期时间
        redisTemplate.expire(menuName,30, TimeUnit.MINUTES);
        if(aBoolean){
            String id= ""+(System.currentTimeMillis()+new Random().nextInt(10000));
            map.put("id",id);
            map.put("code",id);
            int i = menuService.addMenu(map);
            return i;
        }
        return 0;
    }
九、本地数据的持久化
)1、设置编码格式 

)2、首先创建一个文件.properties

)3、存入

public static void main(Stringp[] aggs) throws Exception{
 
 
    Properties prop = new Properties();
 
    FIleInputStream fileInputStream = new         
    FileInputStream("src\\main\\resources\\my.properties");
 
    prop.load(fileInputStream);
 
    
 
    FileOutStream fileOutoutStream = new FileOutStream("src\\main\\resources\\my.properties");
 
    prop.setProperty("张三");
 
    prop.store(fileOutputStream,"");
 
    
    fileOutStream.close();
    fileInpotStream.close();
}
 )4、取出

public void test02() throw Exception{
 
    Properties prop = new Properties();
 
    FileInpotStream fileInputStream = new         
    FileInputStream("src\\main\\resouces\\my.properties");
 
    pro.load(fileInputStream);
 
    Object username = prop.get("zhangsan");
 
    System.out.pring(new String(username.toString).getBytes("ISO-8859-1"),"UTF-8");
    
}
 

十、生成pdf(合同预览,pdf,word 预览或者生成 pdf,下载查看 )
)1、实名认证的接口

url    http://localhost:20000/shimingRenZheng     
请求参数    参数名称    参数类型    参数描述
code    String    身份证号
userName    String    身份证对应的姓名
 

 

 

 

 

@RequestMapping("shimingRenZheng")
public ResponseResult RealNameAuthentication(@RequestBody Map<String,String> map)
 
 
 
响应结果案例:
    {
        code:'响应值200成功、600参数错误、601人证不符',
        msg:'返回的消息信息',
        result:Object:'返回的人证信息'
    }
)2、调用签章进行签章操作

url    http://localhost:20000/addQianZhan     
请求参数    参数名称    参数类型    参数描述
htcode    String    合同编号
content    String    合同内容
 

 

 

 

 

@RequestMapping("addQianZhang")
public ResponseResult addQianZhang(@RequestBody Map<String,String> map)
 
 
 
响应结果案例:
    {
        code:'响应值200成功、603合同签章添加出错',
        msg:'返回的消息信息',
        result:Object:'返回的签章信息'
    }
 )3、电子签章接口  认证合同有效性 接口

url    http://localhost:20000/renZhengQianZhang     
请求参数    参数名称    参数类型    参数描述
htcode    String    合同编号
content    String    合同内容
 

 

 

 

 

@RequestMapping("renZhengQianZhang")
public ResponseResult renZhengQianZhang(@RequestBody Map<String,String> map)
 
 
 
响应结果案例:
    {
        code:'响应值200成功、602合同签章数据有误',
        msg:'返回的消息信息',
        result:Object:'返回的人证的结果'
    }
 十一、前端身份证校验
 )1、先将yanzheng.js导入到store目录下

 

)2、然后在需要使用的页面中加入 import{shenfenzheng,shengenzheng2} from '../../store/yanzheng'

 

1、在需要导入的页面进行导入
2、{} 中写入引入js中的方法名如果想引入多个就用逗号隔开
3、form后面写的是从当前目录中如何定位到需要验证的js
 
import{shenfenzheng,shengenzheng2} from '../../store/yanzheng'
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值