纯静态重构家电售后管理系统(Ajax+HTML+SSM)

纯静态重构家电售后管理系统(Ajax+HTML+SSM) Json的使用 ``` `` 注意: 在使用该**Ajax**接收和传递Json参数时

本文包含相关资料包-----> 点击直达获取<-------

纯静态重构家电售后管理系统(Ajax+HTML+SSM)

Json的使用

```

`` 注意: 在使用该**Ajax**接收和传递Json参数时,需要使用 @ResponseBody`注释函数体

前端传递Json参数为单一对象时

可以直接将参数转换为Json

data:JSON.stringify(thisPage) // data:JSON.stringify(1)===>这样也可以 后端接收参数用String 或Integer即可

@RequestBody Integer thisPage

target域标签无效

原因:在主页面重新给name参数赋值

示例: var name=$.query.get("name");

解决办法:修改参数名,不占用name参数

示例: var name1=$.query.get("name");

Gson包可以将固定类型的字符串型函数转化位Json类型

代码示例:

String JsonObject; if(complaint.getId()!=0){ JsonObject="{\"status\":0}"; }else{ JsonObject="{\"status\":1}"; } Gson gson = new Gson(); return gson.toJson(JsonObject) ; 转换结果: [{"status":0}

当传送的Json由多个类组成时,使用put装载

代码示例:

String JsonObject; if(complaint.getId()!=0){ JsonObject="{\"status\":0}"; }else{ JsonObject="{\"status\":1}"; } Gson gson = new Gson(); return gson.toJson(JsonObject) ; 转换结果: [{"status":0}

mapper操作数据库,insert可以将插入数据后的逐渐返回并set进调用的实体类中

示例:

System.out.println(consult.toString()); System.out.println("插入前consult的id值为:"+consult.getId()); consultService.addConsult(consult); System.out.println("插入后consult的id值为:"+consult.getId()); 日志显示结果:

Consult{id=0, question='1+1=?', answer='2', customername='黄光辉', phone='17624407987'} 插入前consult的id值为:0 Creating a new SqlSession SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@1b6592b7] was not registered for synchronization because synchronization is not active 31-Jul-2020 15:55:37.913 信息 [http-nio-8081-exec-85] com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource. Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, contextClassLoaderSource -> caller, dataSourceName -> 1b61ageab19gu5l52pn1gj|28cc6e98, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> com.mysql.cj.jdbc.Driver, extensions -> {}, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, forceSynchronousCheckins -> false, forceUseNamedDriverClass -> false, identityToken -> 1b61ageab19gu5l52pn1gj|28cc6e98, idleConnectionTestPeriod -> 0, initialPoolSize -> 5, jdbcUrl -> jdbc:mysql://localhost:3306/dbmanager?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 10, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 3, numHelperThreads -> 3, preferredTestQuery -> null, privilegeSpawnedThreads -> false, properties -> {user=******, password=******}, propertyCycle -> 0, statementCacheNumDeferredCloseThreads -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, userOverrides -> {}, usesTraditionalReflectiveProxies -> false ] JDBC Connection [com.mchange.v2.c3p0.impl.NewProxyConnection@3d2b4c13 [wrapping: com.mysql.cj.jdbc.ConnectionImpl@9ef993a]] will not be managed by Spring ==> Preparing: INSERT INTO consult(question,answer,customername,phone) VALUE ( ?, ?, ?, ? ) ==> Parameters: 1+1=?(String), 2(String), 黄光辉(String), 17624407987(String) <== Updates: 1 Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@1b6592b7] 插入后consult的id值为:5

号码判断正则表达式

/*以1开头的11位纯数字*/ function checkMobile(phone){ var regex = /^1\d{10}$/; return regex.test(phone); }

Json在传送带实体类的数据时可以直接读取?(尚不理解)

已理解,被传送至前段时,已经被转换为Json类,所以可以直接使用。

代码示例

逻辑代码

``` Page page=repairService.repairList(current);

Gson gson = new Gson();
String JsonObject=gson.toJson(page);
System.out.println(JsonObject);
return JsonObject ;

``` 实体类代码

private int pageSize=10; //每页10条 private int currentPage; //当前页,页面传递 private int totalSize; //总条数,查询数据库得来 private int totalPage; //共多少页 private int startIndex; //起始记录索引 private List<Map<String, Object>> list; //当前页包含的列表,读取数据库获取 private int num=6; //页面显示的页码个数 private int start; //页面显示页码的起始值 private int end; //页面显示页码的终止值 命令行出结果

``` {"pageSize":10,"currentPage":1,"totalSize":24,"totalPage":0,"startIndex":0,"list":[{"reason":"1","address":"1","phone":"1","productname":"1","id":1,"state":1,"customername":"1","type":0},{"reason":"1","address":"2","phone":"2","productname":"1","id":2,"state":3,"customername":"1","type":0},{"reason":"3","address":"3","phone":"3","productname":"3","id":3,"state":1,"customername":"3","type":0},{"reason":"3","address":"3","phone":"3","productname":"4","id":4,"state":3,"customername":"3","type":0},{"reason":"6","address":"6","phone":"6","productname":"6","id":5,"state":0,"customername":"6","type":0},{"reason":"4","address":"4","phone":"5","productname":"5","id":6,"state":0,"customername":"3","type":0},{"reason":"4","address":"4","phone":"5","productname":"5","id":7,"state":0,"customername":"3","type":0},{"reason":"8","address":"8","phone":"8","productname":"8","id":8,"state":0,"customername":"8","type":0},{"reason":"h","address":"h","phone":"11223","productname":"h","id":9,"state":0,"customername":"h","type":0},{"reason":"ll","address":"ll","phone":"6","productname":"ll","id":10,"state":0,"customername":"ll","type":0}],"num":6,"start":0,"end":0}

```

输出示例

ajax

``` $.ajax({ url:'/waiter/repair/list', data:JSON.stringify(thisPage), type:'POST', dataType:'json', / 声明参数位json类型,便于后台接收时可以识别 / headers:{ Accept:"application/json", "Content-Type":"application/json" }, processData:false, cache:false }).done(function (data) {

            alert(data.pageSize);
            alert(data.list);
            alert(data.list.reason);
            alert(data.list[0].reason);

            }
        );

``` alert输出的值

``` data.pageSize:10

data.list:[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

data.list.reason:undefined

data.list[0].reason:1 ```

Json读取List元素参数

Json参数 "list":[{"name":"3","id":3,"state":0,"username":"3"},{"name":"5","id":5,"state":0,"username":"5"},{"name":"6","id":6,"state":0,"username":"6"}]

js获取方法

for (var key in freeWorkerInfo){ var workerUsername=freeWorkerInfo[key].username; var workerName=freeWorkerInfo[key].name; workerList+="<option value='"+workerUsername+"'>"+workerName+"</option>"; }

String转Json

Gson方法执行类似操作时需要知道转换后的对象类型,操作比较多

public static Object JSONToObject(String json,Class beanClass) { Gson gson =new Gson(); Object res = gson.fromJson(json, beanClass); return res; } alibaba的jackson的jar包可以直接对其转换

/** * jackson.jar包可以将String转换为JsonObject */ JSONObject jsonObject =JSONObject.parseObject(dispatchJson); System.out.println((String) jsonObject.get("productname"));

总结,当返回的字符串Json不是单一对象类,还有其他参数时,Gson并不适用,建议用jaskson, 对象类型单一时,Gson可以完成类的转换,省去了手动转换,建议使用Gson

设置时间格式

SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");

MyBatis中特殊符号(大于、小于等)的处理

第一种写法: * <         小于号(\<) * <=       小于等于(\<=) * >         大于号 (\>)
* >=       大于等于(\>=) * &         取地址符(\&) * '           单引号 (\') * "          双引号 (\")

例如:sql如下:
create_date_time &gt;= #{startTime} and create_date_time &lt;= #{endTime} 在MyBatis中效果:
create_date_time >= #{startTime} and create_date_time <= #{endTime}

第二种写法: * 大于等于 <![CDATA[ >= ]]> * 小于等于 <![CDATA[ <= ]]>

例如:sql如下:
create_date_time <![CDATA[ >= ]]> #{startTime} and create_date_time <![CDATA[ <= ]]> #{endTime}
在MyBatis中效果:
create_date_time >= #{startTime} and create_date_time <= #{endTime}

MyBatis一次执行多个SQL语句

MySQL中

1.在MySQL的链接字符串中添加allowMultiQueries=true字段

<property name="user" value="admin"></property> <property name="password" value="123"></property> <property name="jdbcUrl" value="jdbc:mysql://localhost:3305/dbmanager?useUnicode=true&amp;characterEncoding=utf8&amp;serverTimezone=UTC&amp;allowMultiQueries=true"></property> <property name="driverClass" value="com.mysql.cj.jdbc.Driver"></property> 2.多个语句用分号隔开

<update id="outOfStorage" parameterType="Fixlog" > UPDATE fixlog SET toolname = #{toolname} , toolcount = #{toolcount}, partsname = #{partsname} , partscount = #{partscount} WHERE id = #{id}; UPDATE stock SET count = count-1 WHERE name = #{toolname} and type = 0; UPDATE stock SET count = count-#{partscount} WHERE name = #{partsname} and type = 1; </update>

Oracle中

直接使用begin end 字段

<delete id="delete" parameterType="upc.cbs.HtxxlrEntity"> begin delete from PC_CBS_CONTRACT where contract_id = #{contract_id}; delete from PC_CBS_UPLOAD_FILES where contract_id = #{contract_id} and filetype='合同附件'; delete from PC_CBS_CONTRACT_TEAM where contract_id = #{contract_id}; end; </delete>

Ajax中append() 和before()、after()用法的区别

```

hello

//使用append插入 $("p").append(" world ") //显示结果

hello world

//使用prepend插入 $("p").prepend(" world ") //显示结果

world hello

//使用after插入语句 $("p").after(" world ") //显示结果

hello

world

//使用before插入语句 $("p").before(" world ") //显示结果 world

hello

```

repository接口调用Mybatis操作数据库时,可以使用注解的方式向Mybatis注入字段

  • 使用注解前
    接口端(注入):
    public List<Map<String, Object>> consultList(int startIndex, int pageSize);

Mybatis端(接收): <select id="consultList" resultType="java.util.Map"> SELECT * FROM consult LIMIT #{param1} , #{param2} </select> * 使用注解后
接口端(注入):
public int fixingLogToFixedLog(@Param("fixlog") Fixlog fixlog,@Param("complaintState") int complaintState);

Mybatis端(接收):
```
    <update id="fixingLogToFixedLog" parameterType="Fixlog">
           UPDATE fixlog SET bonus = #{fixlog.bonus},state = #{fixlog.state},reason = #{fixlog.reason},cost = #{fixlog.cost}  WHERE id = #{fixlog.id};
           UPDATE complaint SET state = #{complaintState}  WHERE phone = #{fixlog.customerphone} and productname = #{fixlog.productname} and type = 0;
           UPDATE worker SET state = 0  WHERE username = #{fixlog.username};
   </update>

```

参考文献

  • 基于SOA的ERP分销管理平台的设计与实现(吉林大学·李舒毅)
  • 网上交易系统的设计与实现(厦门大学·杨云)
  • 基于WEB的制造服务管理系统研究与开发(电子科技大学·吕占东)
  • 基于WEB的制造服务管理系统研究与开发(电子科技大学·吕占东)
  • 基于J2EE的德威公司产品销售管理系统的设计与实现(吉林大学·朴海燕)
  • 基于J2EE体系结构的CRM系统的研究与开发(中南大学·杨骐)
  • 网上交易系统的设计与实现(厦门大学·杨云)
  • 基于SSH的CRM系统的研究和设计(重庆交通大学·杨帅)
  • 家电销售企业客户关系管理系统的设计与实现(电子科技大学·刘广宇)
  • 基于SSH的CRM系统的研究和设计(重庆交通大学·杨帅)
  • 基于SOA的ERP分销管理平台的设计与实现(吉林大学·李舒毅)
  • 智能家居信息管理系统的研究(吉林大学·吴胜兵)
  • 基于ExtJS+OSGi网上交易平台的设计与实现(山东大学·孙坤)
  • 基于SSM框架的B2C电商平台的设计与实现(华东交通大学·卢庆胜)
  • 基于SOA的ERP分销管理平台的设计与实现(吉林大学·李舒毅)

本文内容包括但不限于文字、数据、图表及超链接等)均来源于该信息及资料的相关主题。发布者:毕设港湾 ,原文地址:https://bishedaima.com/yuanma/35995.html

相关推荐

发表回复

登录后才能评论