错误总结 和所用的特殊方法 2018/6/6

http://idea.toocruel.net idea破解码

-----------------------------------
Caused by: java.lang.IllegalArgumentException: Mapped Statements collection already contains value for com.runfast.waimai.dao.mapper.RunfastGoodsSellChildrenMapper.updateByPrimaryKeySelective
updateByPrimaryKeySelective这个有两个重名的方法
------------------------------------------------------
bigdecimall转化为是int
BigDecimal a=new BigDecimal(12.88);
int b=a.intValue();
System.out.println(b);//b=12;
------------------------------------
Double 转化为int
Double shopdis=1023.23//类
String s1 = String.valueOf(shopdis);
String s2 = s1.substring(0, s1.indexOf(".")) + s1.substring(s1.indexOf(".")+1);
int i = Integer.parseInt(s2);
--------------------------------
·/driver/loadtakeorders 加载待取订单
·/driver/loadsendorders 加载待送订单
-------------------
int转换bigdecimal
BigDecimal number = new BigDecimal(0);
int value=score;
number=BigDecimal.valueOf((int)value);

----------------------------------
mapper 不能跳转xml时
要清理缓存 idea----file------invalidate caches/restart
----------------------------------------

原符号 < <= > >= & ' "
替换符号 &lt; &lt;= &gt; &gt;= &amp; &apos; &quot;
---------------------------------------
模糊查询 自己整出的方法 ,在控制器中使用“%”+name+"%"
select * from newrunfast.runfast_shopper where
name like #{name}
<if test="work_type !=null">
and work_type=#{work_type}
</if>
<if test="working !=null">
and working=#{working}
</if>
<if test="agentid !=null">
and agentId = #{agentid}
</if>
--------------
String name="云";
String name1="%"+name+"%";
List<RunfastShopper> list=service.findAgentidAndWordtypeAndWorkingAndName(null,1,1,name1); //"%云%"
for (RunfastShopper a:list
) {
System.out.println(a);
}
--------------------------------------------------------
尼玛,今天又出现了时间问题,2009/10/19 00:00:00这是正确的, 测试部门输入的是 2009/10/19 : 00:00:00 就一直报错了,下面的可能用不着,怕以后要用,先记录下来
当用java将字符串格式转换成date类型时,自己定义一个String d = "2010/05/19"时,用语句转换:
SimpleDateFormat sdf = new SimpleDateFormat( "yyyy/MM/dd HH:mm:ss" );
String ddd = "2009/10/19 00:00:00";
try {
Date d = sdf.parse(ddd);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
不会抛出java.text.ParseException: Unparseable date: "2009/10/19 00:00:00"
at java.text.DateFormat.parse(DateFormat.java:337)
at com.come.Dates.main(Dates.java:14)
异常
但是当字符串是用String startDate = request.getParameter("startDate");传过来时会报异常
解决方法:一:Date startReportDate = sdf.parse(startDate.toString());对字符串进行toString 不明白为什么
二:Date start = (Date)sdf.parseObject(startDate);
可以解决
------------------
//退出登录
@RequestMapping(value = "/admin/logout")
public String logout(HttpSession session) throws Exception {
session.removeAttribute("userId");
session.invalidate();
return "redirect:/login";
}
-----------------------------------------
MD5加密时引用digestutils.md5Hex接收前端传过的密码
if(DigestUtils.md5Hex(password).equals(number1.getPassword())){
model.put("msg","密码相同");
---------------------------------------------------------------------------------------------------------------
另外,在prefixOverrrides 、suffixOverrides中都可以指定多个值,用 | 来分隔

<!-- 保存订单 -->
<insert id="saveUser" parameterType="com.changqing.entity.User">
INSERT INTO users
<trim prefix="(" suffix=")" suffixOverrides=",">
id, name, age, description ,
</trim>
VALUE
(#{id},#{name},#{age},#{decription})
</insert>

这时候执行会生成 insert into users(id,name,age) value (……)

所以,你可以发现description后面的那个,会被删除了

在这里还要说明一点,在mysql中的insert语句,INSERT INTO table VALUE()或INSERT INTO table VALUES()都可以,而在oracle中只能使用VALUES
----------------------------------------------------------
Failed to auto-configure a DataSource: 'spring.datasource.url' is not specified and no embedded datasource could be auto-configured
未能自动配置数据源:未指定“Spring,DATAURCE .URL”,没有嵌入的数据源可以自动配置
Resources 没有加载进去而已, mark rirectory as ----Resources root 加载哈就好了
-----------------------------------
平均数,总合撒的,用resultType="map" 接收,返回的是map集合
<select id="findByAgentnameAndbusinessnameAndTime" resultType="map">
select SUM(id),businessname,SUM(goodstotal),SUM(price),SUM(businesspay),SUM(totalpay),SUM(agentget),SUM(shoppermoney),acoefficient from newrunfast.runfast_goods_sell_record where agentId=#{agentid}
<if test="name !=null">and businessName=#{name}</if>
and createTime between #{date1} and #{date2}
limit 0,100
</select>
-----------------------------------------------
遍历Map的四种方法
public static void main(String[] args) {

Map<String, String> map = new HashMap<String, String>();
map.put("1", "value1");
map.put("2", "value2");
map.put("3", "value3");

//第一种:普遍使用,二次取值 这种比较好用
System.out.println("通过Map.keySet遍历key和value:");
for (String key : map.keySet()) {
System.out.println("key= "+ key + " and value= " + map.get(key));
}

//第二种
System.out.println("通过Map.entrySet使用iterator遍历key和value:");
Iterator<Map.Entry<String, String>> it = map.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, String> entry = it.next();
System.out.println("key= " + entry.getKey() + " and value= " + entry.getValue());
}

//第三种:推荐,尤其是容量大时
System.out.println("通过Map.entrySet遍历key和value");
for (Map.Entry<String, String> entry : map.entrySet()) {
System.out.println("key= " + entry.getKey() + " and value= " + entry.getValue());
}
//第四种
System.out.println("通过Map.values()遍历所有的value,但不能遍历key");
for (String v : map.values()) {
System.out.println("value= " + v);
}
}
--------------------------------------------------------
sql语句运算, 思路没问题,但是应该要加上条件判断<if>
<select id="findshopperAndCityAndtime" resultType="map">
SELECT a.agentname,a.shopper,SUM(a.goodstotal) "配送量",SUM(a.shoppermoney) "配送所得金额",
COUNT((a.readytime - a.distime)>0) "超时单" , COUNT((a.readytime - a.distime)>0)/b.countorder "超时率",

COUNT(a.errend=1) "异常取消单",

COUNT(a.errend=1)/b.countstatus9 "异常取消率",
COUNT(b.score &lt;3) "差评单", COUNT(b.score &lt; 3)/b.countbug "差评率"

FROM `runfast_goods_sell_record` a INNER JOIN runfast_distributionassess b ON a.`id`=b.`goodsSellRecordId`
WHERE a.createTime between #{ceateatime1} and #{ceateatime2}
<if test="cityname !=null">
and a.cityname=#{cityname}
</if>
<if test="shoppername !=null">AND a.shopper=#{shoppername}</if>

group by a.shopperid
</select>
------------------------------------------------------------------
这个是时间转换
DateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
String time1="2017-01-01 ";
String time2="2019-01-01";

Date date=dateFormat.parse(time2);

if(1>0){
Calendar Cal=Calendar.getInstance();
Cal.setTime(date);
Cal.add(java.util.Calendar.HOUR_OF_DAY,-24*30); //最近一个月的计算 -24小时*30天
System.out.println("date:"+Cal.getTime());
List<Map<String,BigDecimal>> listmap= sellRecordService.findshopperAndCityAndtime("武汉","小花",Cal.getTime(),date,1);
if(listmap==null){
System.out.println("时间格式不正确");
}else {
System.out.println(listmap);
}
-----------------------------------------------------------------------------
这个是 时间计算 例如昨天, 最近七天, 最近一个月
DateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
String time1="2017-01-01 ";
String time2="2019-01-01";

Date date=dateFormat.parse(time2);
Date date1=new Date();
System.out.println(date1+"当前系统时间");
Calendar Cal=Calendar.getInstance();
Cal.setTime(date); //设置当前系统时间

 

Cal.add(java.util.Calendar.HOUR_OF_DAY,-24*30);// -24小时*30天 负就是倒数30天,不用自己再计算一个月有几天了,爽啊
System.out.println("date:"+Cal.getTime());
List<Map<String,BigDecimal>> listmap= sellRecordService.findshopperAndCityAndtime(null,null,Cal.getTime(),date1,1);//查询最近一个月的数据统计
-----------------------------------------------
此为统计联表查询 ,
<select id="findshopperAndCityAndtime" resultType="map">
SELECT a.agentname,a.shopper,a.shoppermobile,SUM(a.status=8) "有效完成单",SUM(a.shoppermoney) "配送所得金额",
sum((a.readytime - a.distime)>0) "超时单" , sum((a.readytime - a.distime)>0)/sum(a.readytime >0) "超时率",

sum(a.errend=1) "异常取消单",

sum(a.errend=1)/sum(a.status=9 ) "异常取消率",

(sum(b.score = 1)+sum(b.score=2)) "差评单",


(sum(b.score = 1)+sum(b.score=2))/sum(b.score &lt;6) "差评率"

FROM runfast_distributionassess b INNER JOIN `runfast_goods_sell_record` a ON a.`id`=b.`goodsSellRecordId`
WHERE a.createTime between #{ceateatime1} and #{ceateatime2}
<if test="cityname !=null">
and a.cityname=#{cityname}
</if>
<if test="shoppername !=null">AND a.shopper=#{shoppername}</if>

group by a.shopperid
</select>

 

posted @ 2018-06-06 10:35  横扫天下IT  阅读(253)  评论(0编辑  收藏  举报