NutzCN Logo
问答 关于nutzbook新增用户user_id为空
发布于 3123天前 作者 qq_6b8e56db 2313 次浏览 复制 上一个帖子 下一个帖子
标签:

在mysql下正常,但切换到sqlserver下的时候却死活为空。

/**
     * 新增用户
     *
     * @param user
     * @param profile
     * @param unitId
     * @param roleIds
     */
    @Aop(TransAop.READ_COMMITTED)
    public void save(Sys_user user, Sys_user_profile profile, String unitId, String[] roleIds) {
        RandomNumberGenerator rng = new SecureRandomNumberGenerator();
        String salt = rng.nextBytes().toBase64();
        String hashedPasswordBase64 = new Sha256Hash(user.getPassword(), salt, 1024).toBase64();
        user.setSalt(salt);
        user.setPassword(hashedPasswordBase64);
        user.setUsername(user.getUsername().trim());
        Sys_user u = dao().insert(user);
        profile.setUserId(u.getId());
        dao().insert(profile);
        if (!Strings.isEmpty(unitId)) {
            dao().insert("sys_user_unit", Chain.make("user_id", u.getId()).add("unit_id", unitId));
        }
        for (String roleId : roleIds) {
            dao().insert("sys_user_role", Chain.make("user_id", u.getId()).add("role_id", roleId));
        }
    }
11 回复

代码看不出啥,不知道你说哪个地方的user_id是null

@wendal 这个是nutzbook的demo代码,Sys user有个字段是user id 不知道这个Long型的user id是哪里插入的

@qq_6b8e56db 这命名肯定不是nutzbook啊

@wendal 我看这个service是去年6月份写的

/**
 * Created by Wizzer.cn on 2015/6/30.
 */
@IocBean(args = {"refer:dao"})
public class UserService extends BaseService<Sys_user> {
    public UserService(Dao dao) {
        super(dao);
    }

@wendal 说错了,是NutzWk 2.0

@qq_6b8e56db 这是nutzwk的代码,我就是这命名规则跟我的风格完全不一样

sqlserver版本多少,另外贴pojo

@wendal

package cn.wizzer.modules.sys.bean;

import cn.wizzer.common.service.core.BasePojo;
import org.nutz.dao.entity.annotation.*;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by Wizzer.cn on 2015/6/27.
 */
@Table("sys_user")
@TableIndexes({@Index(name = "INDEX_USERNAME", fields = {"username"}, unique = true)})
public class Sys_user extends BasePojo implements Serializable {
    private static final long serialVersionUID = 1L;
    @Column
    @Name
    @Comment("ID")
    @ColDefine(type = ColType.VARCHAR, width = 64)
    @Prev(els = {@EL("uuid()")})
    private String id;
    @Column
    @Comment("登录名")
    @ColDefine(type = ColType.VARCHAR, width = 120)
    private String username;
    @Column("passwd")
    @Comment("密码")
    @ColDefine(type = ColType.VARCHAR, width = 128)
    private String password;// transient 修饰符可让此字段不在对象里显示
    @Column
    @Comment("加盐")
    @ColDefine(type = ColType.VARCHAR, width = 50)
    private String salt;
    @Column("is_online")
    @Comment("是否在线")
    @ColDefine(type = ColType.BOOLEAN)
    private boolean online;
    @Column("is_locked")
    @Comment("是否锁定")
    @ColDefine(type = ColType.BOOLEAN)
    private boolean locked;
    @Comment("系统管理员")
    @ColDefine(type = ColType.BOOLEAN)
    private boolean system;
    @Column("register_ip")
    @ColDefine(type = ColType.VARCHAR, width = 15)
    private String registerIp;
    @Prev(els = @EL("$me.now()"))
    @Column("login_time")
    @Comment("登陆时间")
    protected Date loginTime;
    @Column("login_ip")
    @Comment("登陆IP")
    @ColDefine(type = ColType.VARCHAR, width = 15)
    private String loginIp;
    @Column("login_count")
    @Comment("登陆次数")
    @ColDefine(type = ColType.INT)
    private int loginCount;
    @Column("login_menu")
    @Comment("登陆菜单")
    @ColDefine(type = ColType.VARCHAR, width = 100)
    private String loginMenu;
    @Column("login_theme")
    @Comment("登陆皮肤")
    @ColDefine(type = ColType.VARCHAR, width = 100)
    private String loginTheme;
    @Column("login_sidebar")
    private boolean loginSidebar;
    @Column("login_boxed")
    private boolean loginBoxed;
    @Column("login_scroll")
    private boolean loginScroll;
    @ManyMany(from = "user_id", relation = "sys_user_role", target = Sys_role.class, to = "role_id")
    protected List<Sys_role> roles;
    @ManyMany(from = "user_id", relation = "sys_user_unit", target = Sys_role.class, to = "unit_id")
    protected List<Sys_unit> units;
    @One(target = Sys_user_profile.class, field = "id", key = "userId")
    protected Sys_user_profile profile;
    protected List<Sys_menu> menus;
    protected List<Sys_menu> firstMenus;
    protected Map<String, List<Sys_menu>> secondMenus;
    
    
    @Column("user_id")
    @Comment("用户ID")
    private Long userId;
    
    public String getId() {
        return id;
    }

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

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

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

    public String getSalt() {
        return salt;
    }

    public void setSalt(String salt) {
        this.salt = salt;
    }

    public boolean isLocked() {
        return locked;
    }

    public void setLocked(boolean locked) {
        this.locked = locked;
    }

    public String getLoginIp() {
        return loginIp;
    }

    public void setLoginIp(String loginIp) {
        this.loginIp = loginIp;
    }

    public int getLoginCount() {
        return loginCount;
    }

    public void setLoginCount(int loginCount) {
        this.loginCount = loginCount;
    }

    public Date getLoginTime() {
        return loginTime;
    }

    public void setLoginTime(Date loginTime) {
        this.loginTime = loginTime;
    }

    public String getRegisterIp() {
        return registerIp;
    }

    public void setRegisterIp(String registerIp) {
        this.registerIp = registerIp;
    }

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

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

    public boolean isSystem() {
        return system;
    }

    public void setSystem(boolean system) {
        this.system = system;
    }

    public String getLoginMenu() {
        return loginMenu;
    }

    public void setLoginMenu(String loginMenu) {
        this.loginMenu = loginMenu;
    }

    public String getLoginTheme() {
        return loginTheme;
    }

    public void setLoginTheme(String loginTheme) {
        this.loginTheme = loginTheme;
    }

    public Sys_user_profile getProfile() {
        return profile;
    }

    public void setProfile(Sys_user_profile profile) {
        this.profile = profile;
    }

    public List<Sys_menu> getMenus() {
        return menus;
    }

    public void setMenus(List<Sys_menu> menus) {
        this.menus = menus;
    }

    public List<Sys_menu> getFirstMenus() {
        return firstMenus;
    }

    public void setFirstMenus(List<Sys_menu> firstMenus) {
        this.firstMenus = firstMenus;
    }

    public Map<String, List<Sys_menu>> getSecondMenus() {
        return secondMenus;
    }

    public void setSecondMenus(Map<String, List<Sys_menu>> secondMenus) {
        this.secondMenus = secondMenus;
    }

    public boolean isLoginSidebar() {
        return loginSidebar;
    }

    public void setLoginSidebar(boolean loginSidebar) {
        this.loginSidebar = loginSidebar;
    }

    public boolean isLoginBoxed() {
        return loginBoxed;
    }

    public void setLoginBoxed(boolean loginBoxed) {
        this.loginBoxed = loginBoxed;
    }

    public boolean isLoginScroll() {
        return loginScroll;
    }

    public void setLoginScroll(boolean loginScroll) {
        this.loginScroll = loginScroll;
    }

    public List<Sys_unit> getUnits() {
        return units;
    }

    public void setUnits(List<Sys_unit> units) {
        this.units = units;
    }

    public boolean isOnline() {
        return online;
    }

    public void setOnline(boolean online) {
        this.online = online;
    }

	public Long getUserId() {
		return userId;
	}

	public void setUserId(Long userId) {
		this.userId = userId;
	}
    
    
}

@wendal SQLSERVER版本是 2014

@wendal 好了,我解决了,这个是个自增ID

@Column("user_id")
    @Comment("用户ID")
    @Prev(@SQL(db=DB.SQLSERVER, value = "select max(user_id)+1 from sys_user"))
    private Long userId;

神奇,为啥没有加@Id呢

@wendal 这个得问nutzwk了

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