NutzCN Logo
问答 updateWithVersion插入的时候可以设置值默认0,但是跟更新的时候version不能+1
发布于 2472天前 作者 naxxm 1997 次浏览 复制 上一个帖子 下一个帖子
标签:

更新updateWith

@Aop(TransAop.READ_COMMITTED)
	public void save(final JSONObject params, final Class<?> type) {

		Table table;
		try {
			table = Transform.jsonToTable(params.getJSONObject("data"));
			// 更新
			Object list = Transform2.tableToPojo(table, RowState.EDIT, type);
			//myDao.update(list, DataUtils2.arrayJoin4Regex(table.getColumnNames().toArray(), "%s", "|"));
			myDao.updateWithVersion(list,FieldFilter.create(type, DataUtils2.arrayJoin4Regex(table.getColumnNames().toArray(), "%s", "|")));//版本号不更新
			// 添加
			list = Transform2.tableToPojo(table, RowState.NEW, type);
			myDao.insert(list);//可以设置默认版本号为0
			// 删除
			list = Transform2.tableToPojo(table, RowState.DELETE, type);
			myDao.delete(list);
		} catch (ParseException e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
			Log.debug("更新删除添加报错!");
		}
	}
5 回复

日志贴一下

@wendal version = true,用户注册插入时,version自动为0;但是当修改密码时version没有得到+1,以下时用户注册、修改密码的日志~

2018-02-08 15:39:38 Found mapping for [POST] path=/getMobileCode : TestCustomRealmMd5.getMobileCode(TestCustomRealmMd5.java:133)
2018-02-08 15:39:38 Get 'testCustomRealmMd5'<class com.naxxm.shiro.handlers.TestCustomRealmMd5>
697281
您的验证码为:697281,该验证码 5 分钟内有效,请勿泄漏于他人。【迅航收银】
2018-02-08 15:39:46 Found mapping for [POST] path=/register : TestCustomRealmMd5.register(TestCustomRealmMd5.java:163)
2018-02-08 15:39:46 Get 'testCustomRealmMd5'<class com.naxxm.shiro.handlers.TestCustomRealmMd5>
2018-02-08 15:39:46 select * from(select row_number()over(order by __tc__)__rn__,* from(select top 1 0 __tc__,    * FROM t_sys_company  WHERE mobile=?)t)tt where __rn__ > 0 order by __rn__ 
    |           1 |
    |-------------|
    | 13800000000 |
  For example:> "select * from(select row_number()over(order by __tc__)__rn__,* from(select top 1 0 __tc__,    * FROM t_sys_company  WHERE mobile='13800000000')t)tt where __rn__ > 0 order by __rn__ "
2018-02-08 15:39:46 // NOT SQL // ElFieldMacro=uuid()
2018-02-08 15:39:46 INSERT INTO t_sys_company(uuid,version,bm,mc,contacts,mobile,phone,QQ,WeChat,address,regDate,matDate,userNum,onlineNum,edition,loginDate,DBInfo,state,customer,saleMan,rent,industry,region,remarks) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) 
    |                                1 | 2 |           3 |    4 |    5 |           6 |    7 |    8 |    9 |   10 |   11 |   12 |   13 |   14 |   15 |   16 |                                                        17 |   18 |   19 |   20 |   21 |   22 |   23 |   24 |
    |----------------------------------|---|-------------|------|------|-------------|------|------|------|------|------|------|------|------|------|------|-----------------------------------------------------------|------|------|------|------|------|------|------|
    | ef34a014873447d8a66f281c64af0cc0 | 0 | 13800000000 | NULL | NULL | 13800000000 | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | jdbc:jtds:sqlserver://127.0.0.1:1433/companyDB_01,sa,0000 | NULL | NULL | NULL | NULL | NULL | NULL | NULL |
  For example:> "INSERT INTO t_sys_company(uuid,version,bm,mc,contacts,mobile,phone,QQ,WeChat,address,regDate,matDate,userNum,onlineNum,edition,loginDate,DBInfo,state,customer,saleMan,rent,industry,region,remarks) VALUES('ef34a014873447d8a66f281c64af0cc0',0,'13800000000',NULL,NULL,'13800000000',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'jdbc:jtds:sqlserver://127.0.0.1:1433/companyDB_01,sa,0000',NULL,NULL,NULL,NULL,NULL,NULL,NULL) "
2018-02-08 15:39:46 select * from(select row_number()over(order by __tc__)__rn__,* from(select top 1 0 __tc__,    * FROM t_sys_company  WHERE bm=?)t)tt where __rn__ > 0 order by __rn__ 
    |           1 |
    |-------------|
    | 13800000000 |
  For example:> "select * from(select row_number()over(order by __tc__)__rn__,* from(select top 1 0 __tc__,    * FROM t_sys_company  WHERE bm='13800000000')t)tt where __rn__ > 0 order by __rn__ "
------------------------------------------------------------------------------------------------
null---jdbc:jtds:sqlserver:------127.0.0.1:1433---companyDB_01
------------------------------------------------------------------------------------------------
2018-02-08 15:39:46 select * from(select row_number()over(order by __tc__)__rn__,* from(select top 1 0 __tc__,    * FROM t_sys_db  WHERE db=?)t)tt where __rn__ > 0 order by __rn__ 
    |            1 |
    |--------------|
    | companyDB_01 |
  For example:> "select * from(select row_number()over(order by __tc__)__rn__,* from(select top 1 0 __tc__,    * FROM t_sys_db  WHERE db='companyDB_01')t)tt where __rn__ > 0 order by __rn__ "
--->数据库:true
--->数据库已经初始化
------------------------------------------------------------------------------------------------
null---jdbc:jtds:sqlserver://127.0.0.1:1433/companyDB_01---sa---0000
------------------------------------------------------------------------------------------------
--->系统数据库:公司信息正常!
2018-02-08 15:39:46 // NOT SQL // ElFieldMacro=uuid()
2018-02-08 15:39:46 INSERT INTO t_company_employee(uuid,version,bm,gs_bm,md_bm,name,password,authsalt,sex,mobile,wage,position,entrydate,sales,state) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) 
    |                                1 | 2 |     3 |           4 |    5 |     6 |                                7 |      8 |    9 |          10 |   11 |   12 |   13 |   14 |   15 |
    |----------------------------------|---|-------|-------------|------|-------|----------------------------------|--------|------|-------------|------|------|------|------|------|
    | 9fd6fb8954de4ab9810d50070c03913e | 0 | 10000 | 13800000000 | NULL | admin | ee626fa3b3641f8bd6a46949984812e3 | e4N99E | NULL | 13800000000 | NULL | NULL | NULL | NULL | NULL |
  For example:> "INSERT INTO t_company_employee(uuid,version,bm,gs_bm,md_bm,name,password,authsalt,sex,mobile,wage,position,entrydate,sales,state) VALUES('9fd6fb8954de4ab9810d50070c03913e',0,'10000','13800000000',NULL,'admin','ee626fa3b3641f8bd6a46949984812e3','e4N99E',NULL,'13800000000',NULL,NULL,NULL,NULL,NULL) "
2018-02-08 15:39:46 201---用户注册成功!
您的工号:10000,密码:1375F9请及时修改初始密码,妥善保管好您的用户信息。【迅航收银】
2018-02-08 15:39:56 Found mapping for [POST] path=/login : TestCustomRealmMd5.login(TestCustomRealmMd5.java:72)
2018-02-08 15:39:56 Get 'testCustomRealmMd5'<class com.naxxm.shiro.handlers.TestCustomRealmMd5>
com.naxxm.utils.JSONResult@1d870f1
--->步骤一:公司编码:13800000000用户输入用户名:10000,密码:1375F9
2018-02-08 15:39:56 select * from(select row_number()over(order by __tc__)__rn__,* from(select top 1 0 __tc__,    * FROM t_sys_company  WHERE bm=?)t)tt where __rn__ > 0 order by __rn__ 
    |           1 |
    |-------------|
    | 13800000000 |
  For example:> "select * from(select row_number()over(order by __tc__)__rn__,* from(select top 1 0 __tc__,    * FROM t_sys_company  WHERE bm='13800000000')t)tt where __rn__ > 0 order by __rn__ "
------------------------------------------------------------------------------------------------
null---jdbc:jtds:sqlserver:------127.0.0.1:1433---companyDB_01
------------------------------------------------------------------------------------------------
2018-02-08 15:39:56 select * from(select row_number()over(order by __tc__)__rn__,* from(select top 1 0 __tc__,    * FROM t_sys_db  WHERE db=?)t)tt where __rn__ > 0 order by __rn__ 
    |            1 |
    |--------------|
    | companyDB_01 |
  For example:> "select * from(select row_number()over(order by __tc__)__rn__,* from(select top 1 0 __tc__,    * FROM t_sys_db  WHERE db='companyDB_01')t)tt where __rn__ > 0 order by __rn__ "
--->数据库:true
--->数据库已经初始化
公司编码:13800000000
------------------------------------------------------------------------------------------------
null---jdbc:jtds:sqlserver://127.0.0.1:1433/companyDB_01---sa---0000
------------------------------------------------------------------------------------------------
--->系统数据库:公司信息正常!
2018-02-08 15:39:56 SELECT * FROM t_company_employee  WHERE bm=? AND gs_bm=?
    |     1 |           2 |
    |-------|-------------|
    | 10000 | 13800000000 |
  For example:> "SELECT * FROM t_company_employee  WHERE bm='10000' AND gs_bm='13800000000'"
------------------------------------------------------------------------------------------------
null---jdbc:jtds:sqlserver://127.0.0.1:1433/companyDB_01---sa---0000
------------------------------------------------------------------------------------------------
--->系统数据库:公司信息正常!
2018-02-08 15:39:56 SELECT * FROM t_company_employee  WHERE bm=? AND gs_bm=?
    |     1 |           2 |
    |-------|-------------|
    | 10000 | 13800000000 |
  For example:> "SELECT * FROM t_company_employee  WHERE bm='10000' AND gs_bm='13800000000'"
2018-02-08 15:39:56 SELECT * FROM t_company_role  WHERE bm IN (SELECT role_bm FROM t_company_employee_role WHERE employee_bm='9fd6fb8954de4ab9810d50070c03913e')
用户信息:admin
用户权限:[]
2018-02-08 15:39:56 com.naxxm.bean.company.ActiveUser@c63dcd
org.apache.shiro.session.UnknownSessionException: There is no session with id [pbp1edpbkojtdrjh6uk8vncqqg]
	at org.apache.shiro.session.mgt.eis.AbstractSessionDAO.readSession(AbstractSessionDAO.java:170)
	at org.apache.shiro.session.mgt.eis.CachingSessionDAO.readSession(CachingSessionDAO.java:261)
	at org.apache.shiro.session.mgt.DefaultSessionManager.retrieveSessionFromDataSource(DefaultSessionManager.java:236)
	at org.apache.shiro.session.mgt.DefaultSessionManager.retrieveSession(DefaultSessionManager.java:222)
	at org.apache.shiro.session.mgt.AbstractValidatingSessionManager.doGetSession(AbstractValidatingSessionManager.java:118)
	at org.apache.shiro.session.mgt.AbstractNativeSessionManager.lookupSession(AbstractNativeSessionManager.java:148)
	at org.apache.shiro.session.mgt.AbstractNativeSessionManager.getSession(AbstractNativeSessionManager.java:140)
	at com.naxxm.shiro.filters.KickoutSessionControlFilter.onAccessDenied(KickoutSessionControlFilter.java:109)
	at org.apache.shiro.web.filter.AccessControlFilter.onAccessDenied(AccessControlFilter.java:133)
	at org.apache.shiro.web.filter.AccessControlFilter.onPreHandle(AccessControlFilter.java:162)
	at org.apache.shiro.web.filter.PathMatchingFilter.isFilterChainContinued(PathMatchingFilter.java:203)
	at org.apache.shiro.web.filter.PathMatchingFilter.preHandle(PathMatchingFilter.java:178)
	at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:131)
	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
	at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
	at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
	at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
	at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
	at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
	at java.lang.Thread.run(Thread.java:745)
2018-02-08 15:40:05 Found mapping for [POST] path=/naxxm/user/changePWD : UserAction.changePWD(UserAction.java:72)
2018-02-08 15:40:05 Get 'userAction'<class com.naxxm.action.UserAction>
------------------------------------------------------------------------------------------------
null---jdbc:jtds:sqlserver://127.0.0.1:1433/companyDB_01---sa---0000
------------------------------------------------------------------------------------------------
--->系统数据库:公司信息正常!
2018-02-08 15:40:05 select * from(select row_number()over(order by __tc__)__rn__,* from(select top 1 0 __tc__,    * FROM t_company_employee  WHERE bm=?)t)tt where __rn__ > 0 order by __rn__ 
    |     1 |
    |-------|
    | 10000 |
  For example:> "select * from(select row_number()over(order by __tc__)__rn__,* from(select top 1 0 __tc__,    * FROM t_company_employee  WHERE bm='10000')t)tt where __rn__ > 0 order by __rn__ "
------------------------------------------------------------------------------------------------
null---jdbc:jtds:sqlserver://127.0.0.1:1433/companyDB_01---sa---0000
------------------------------------------------------------------------------------------------
--->系统数据库:公司信息正常!
2018-02-08 15:40:05 UPDATE t_company_employee SET version=?,bm=?,gs_bm=?,md_bm=?,name=?,password=?,authsalt=?,sex=?,mobile=?,wage=?,position=?,entrydate=?,sales=?,state=?  WHERE uuid=?
    | 1 |     2 |           3 |    4 |     5 |                                6 |      7 |    8 |           9 |   10 |   11 |   12 |   13 |   14 |                               15 |
    |---|-------|-------------|------|-------|----------------------------------|--------|------|-------------|------|------|------|------|------|----------------------------------|
    | 0 | 10000 | 13800000000 | NULL | admin | 17b0b875169cf6a68cd0394054f83e2a | h2n735 | NULL | 13800000000 | NULL | NULL | NULL | NULL | NULL | 9fd6fb8954de4ab9810d50070c03913e |
  For example:> "UPDATE t_company_employee SET version=0,bm='10000',gs_bm='13800000000',md_bm=NULL,name='admin',password='17b0b875169cf6a68cd0394054f83e2a',authsalt='h2n735',sex=NULL,mobile='13800000000',wage=NULL,position=NULL,entrydate=NULL,sales=NULL,state=NULL  WHERE uuid='9fd6fb8954de4ab9810d50070c03913e'"
2018-02-08 15:40:05 201---密码修改成功!

t_company_employee 对应的pojo类贴一下
package com.naxxm.bean.company;

import java.sql.Date;
import java.util.List;

import org.nutz.dao.entity.annotation.ColDefine;
import org.nutz.dao.entity.annotation.ColType;
import org.nutz.dao.entity.annotation.Column;
import org.nutz.dao.entity.annotation.Comment;
import org.nutz.dao.entity.annotation.EL;
import org.nutz.dao.entity.annotation.ManyMany;
import org.nutz.dao.entity.annotation.Name;
import org.nutz.dao.entity.annotation.PK;
import org.nutz.dao.entity.annotation.Prev;
import org.nutz.dao.entity.annotation.Table;

@Table("t_company_employee")
//@PK(value = { "id", "bm" })
public class Employee {
	@ManyMany(relation = "t_company_employee_role", from = "employee_bm", to = "role_bm")
	private List<Role> roles;
	
	@Name
	@Prev(els = { @EL("uuid()") })
	@Comment("uuid主键唯一")
	@ColDefine(type = ColType.VARCHAR, width = 32)
	@Column("uuid")
	private String id;

	@Comment("版本")
	@Column(version = true)
	private long version;

	@Comment("员工编号")
	@ColDefine(type = ColType.VARCHAR, width = 32)
	@Column
	private String bm;

	@Comment("公司编号")
	@ColDefine(type = ColType.VARCHAR, width = 16)
	@Column
	private String gs_bm;

	@Comment("所属分店")
	@ColDefine(type = ColType.VARCHAR, width = 16)
	@Column
	private String md_bm;

	@Comment("员工姓名")
	@ColDefine(type = ColType.VARCHAR, width = 20)
	@Column
	private String name;

	@Comment("登录密码")
	@ColDefine(type = ColType.VARCHAR, width = 32)
	@Column
	private String password;

	@Comment("盐值")
	@ColDefine(type = ColType.VARCHAR, width = 6)
	@Column
	private String authsalt;

	@Comment("性别")
	@ColDefine(type = ColType.VARCHAR, width = 2)
	@Column
	private String sex;

	@Comment("手机号")
	@ColDefine(type = ColType.VARCHAR, width = 30)
	@Column
	private String mobile;

	@Comment("基本工资")
	@ColDefine(type = ColType.FLOAT, width = 8, precision = 2)
	@Column
	private String wage;

	@Comment("岗位")
	@ColDefine(type = ColType.VARCHAR, width = 20)
	@Column
	private String position;

	@Comment("入职日期")
	@ColDefine(type = ColType.DATETIME)
	@Column
	private Date entrydate;

	@Comment("参与销售")
	@ColDefine(type = ColType.INT, width = 1)
	@Column
	private Integer sales;

	@Comment("是否在职")
	@ColDefine(type = ColType.INT, width = 1)
	@Column
	private Integer state;

	public List<Role> getRoles() {
		return roles;
	}

	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public long getVersion() {
		return version;
	}

	public void setVersion(long version) {
		this.version = version;
	}

	public String getBm() {
		return bm;
	}

	public void setBm(String bm) {
		this.bm = bm;
	}

	public String getGs_bm() {
		return gs_bm;
	}

	public void setGs_bm(String gs_bm) {
		this.gs_bm = gs_bm;
	}

	public String getMd_bm() {
		return md_bm;
	}

	public void setMd_bm(String md_bm) {
		this.md_bm = md_bm;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getAuthsalt() {
		return authsalt;
	}

	public void setAuthsalt(String authsalt) {
		this.authsalt = authsalt;
	}

	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public String getWage() {
		return wage;
	}

	public void setWage(String wage) {
		this.wage = wage;
	}

	public String getPosition() {
		return position;
	}

	public void setPosition(String position) {
		this.position = position;
	}

	public Date getEntrydate() {
		return entrydate;
	}

	public void setEntrydate(Date entrydate) {
		this.entrydate = entrydate;
	}

	public Integer getSales() {
		return sales;
	}

	public void setSales(Integer sales) {
		this.sales = sales;
	}

	public Integer getState() {
		return state;
	}

	public void setState(Integer state) {
		this.state = state;
	}

}

看上去没啥问题,单个对象updateWithVersion试试

添加回复
请先登陆
回到顶部