NutzCN Logo
问答 org.nutz.lang.FailToGetValueException
发布于 2969天前 作者 Hamming 2397 次浏览 复制 上一个帖子 下一个帖子
标签:

nutzwk代码生成器生成代码,修改保存 错误信息如下,数据更新成功了 实体类也声明了ID了 为什么还报错呢

2016-10-06 09:21:56,938 org.nutz.mvc.impl.UrlMappingImpl.get(UrlMappingImpl.java:101) DEBUG - Found mapping for [POST] path=/private/app/app_shopping_carts/editDo : AppShoppingCartController.editDo(AppShoppingCartController.java:77)
2016-10-06 09:21:56,938 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'permission'<class nuoshang.bluejay.common.shiro.view.Permission>
2016-10-06 09:21:56,938 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'dateUtil'<class nuoshang.bluejay.common.util.DateUtil>
2016-10-06 09:21:56,939 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'stringUtil'<class nuoshang.bluejay.common.util.StringUtil>
2016-10-06 09:21:56,939 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'appShoppingCartController'<class nuoshang.bluejay.modules.app.controllers.AppShoppingCartController>
2016-10-06 09:21:56,940 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - UPDATE app_shopping_cart SET userId=?,productId=?,productNum=?,typeId=?,typeImgUrl=?,proPrice=?,opAt=?  WHERE cart_id=?
    | 1 | 2 | 3 | 4 |        5 |     6 |          7 | 8 |
    |---|---|---|---|----------|-------|------------|---|
    | 1 | 1 | 1 | t | /sffffff | 998.0 | 1475716916 | 1 |
  For example:> "UPDATE app_shopping_cart SET userId=1,productId=1,productNum=1,typeId='t',typeImgUrl='/sffffff',proPrice=998.0,opAt=1475716916  WHERE cart_id=1"
2016-10-06 09:21:56,993 nuoshang.bluejay.common.processor.LogTimeProcessor.process(LogTimeProcessor.java:26) DEBUG - [POST]URI=/private/app/app_shopping_carts/editDo 55ms
2016-10-06 09:21:56,993 org.nutz.mvc.impl.processor.FailProcessor.process(FailProcessor.java:28) WARN  - Error@/private/app/app_shopping_carts/editDo :
org.nutz.lang.FailToGetValueException: Fail to get value for [nuoshang.bluejay.modules.app.models.App_shopping_cart]->[id]
	at org.nutz.lang.Mirror.makeGetValueException(Mirror.java:763)
	at org.nutz.lang.Mirror.getValue(Mirror.java:826)
	at org.nutz.el.opt.object.AccessOpt.calculate(AccessOpt.java:46)
	at org.nutz.el.arithmetic.RPN.calculate(RPN.java:55)
	at org.nutz.el.arithmetic.RPN.calculate(RPN.java:38)
	at org.nutz.el.El.eval(El.java:30)
	at nuoshang.bluejay.common.services.log.SysLogAopInterceptor.doLog(SysLogAopInterceptor.java:78)
	at nuoshang.bluejay.common.services.log.SysLogAopInterceptor.filter(SysLogAopInterceptor.java:62)
	at org.nutz.aop.InterceptorChain.doChain(InterceptorChain.java:60)
	at nuoshang.bluejay.modules.app.controllers.AppShoppingCartController$$NUTZAOP.editDo(AppShoppingCartController.java:1)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:25)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:33)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at nuoshang.bluejay.common.processor.XssSqlFilterProcessor.process(XssSqlFilterProcessor.java:35)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at nuoshang.bluejay.common.processor.NutShiroProcessor.process(NutShiroProcessor.java:52)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at nuoshang.bluejay.common.processor.GlobalsSettingProcessor.process(GlobalsSettingProcessor.java:36)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at nuoshang.bluejay.common.processor.LogTimeProcessor.process(LogTimeProcessor.java:21)
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:198)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at nuoshang.bluejay.common.filter.RouteFilter.doFilter(RouteFilter.java:33)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)
	at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
	at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
	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:192)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:522)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:1110)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:785)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1425)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NoSuchMethodException: Fail to find getter for [nuoshang.bluejay.modules.app.models.App_shopping_cart]->[id]
	at sun.reflect.GeneratedConstructorAccessor46.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at org.nutz.lang.born.ConstructorBorning.born(ConstructorBorning.java:17)
	at org.nutz.lang.born.BornContext.doBorn(BornContext.java:60)
	at org.nutz.lang.Mirror.born(Mirror.java:990)
	at org.nutz.lang.Lang.makeThrow(Lang.java:150)
	at org.nutz.lang.Mirror.getGetter(Mirror.java:251)
	at org.nutz.lang.Mirror.getGetter(Mirror.java:197)
	at org.nutz.lang.Mirror.getValue(Mirror.java:804)
	... 71 more

package nuoshang.bluejay.modules.app.controllers;

import nuoshang.bluejay.common.annotation.SLog;
import nuoshang.bluejay.common.base.Result;
import nuoshang.bluejay.common.filter.PrivateFilter;
import nuoshang.bluejay.common.page.DataTableColumn;
import nuoshang.bluejay.common.page.DataTableOrder;
import nuoshang.bluejay.modules.app.models.App_shopping_cart;
import nuoshang.bluejay.modules.app.services.AppShoppingCartService;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.nutz.dao.Cnd;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.Strings;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.mvc.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@IocBean
@At("/private/app/app_shopping_carts")
@Filters({@By(type = PrivateFilter.class)})
public class AppShoppingCartController {
	private static final Log log = Logs.get();
	@Inject
	private AppShoppingCartService appShoppingCartService;

	@At("")
	@Ok("beetl:/private/app/app_shopping_carts/index.html")
	@RequiresAuthentication
	public void index() {

	}

	@At
	@Ok("json:full")
	@RequiresAuthentication
	public Object data(@Param("length") int length, @Param("start") int start, @Param("draw") int draw, @Param("::order") List<DataTableOrder> order, @Param("::columns") List<DataTableColumn> columns) {
		Cnd cnd = Cnd.NEW();
    	return appShoppingCartService.data(length, start, draw, order, columns, cnd, null);
    }

    @At
    @Ok("beetl:/private/app/app_shopping_carts/add.html")
    @RequiresAuthentication
    public void add() {

    }

    @At
    @Ok("json")
    @SLog(tag = "新建App_shopping_cart", msg = "")
    public Object addDo(@Param("..") App_shopping_cart appShoppingCart, HttpServletRequest req) {
		try {
			appShoppingCartService.insert(appShoppingCart);
			return Result.success("system.success");
		} catch (Exception e) {
			return Result.error("system.error");
		}
    }

    @At("/edit/?")
    @Ok("beetl:/private/app/app_shopping_carts/edit.html")
    @RequiresAuthentication
    public Object edit(Integer id) {
		return appShoppingCartService.fetch(id);
    }

    @At
    @Ok("json")
    @SLog(tag = "修改App_shopping_cart", msg = "ID:${args[0].id}")
    public Object editDo(@Param("..") App_shopping_cart appShoppingCart, HttpServletRequest req) {
		try {

			appShoppingCart.setOpAt((int) (System.currentTimeMillis() / 1000));
			appShoppingCartService.updateIgnoreNull(appShoppingCart);
			return Result.success("system.success");
		} catch (Exception e) {
			return Result.error("system.error");
		}
    }


    @At({"/delete","/delete/?"})
    @Ok("json")
    @SLog(tag = "删除App_shopping_cart", msg = "ID:${args[2].getAttribute('id')}")
    public Object delete(String id, @Param("ids") String[] ids ,HttpServletRequest req) {
		try {
			if(ids!=null&&ids.length>0){
				appShoppingCartService.delete(ids);
    			req.setAttribute("id", org.apache.shiro.util.StringUtils.toString(ids));
			}else{
				appShoppingCartService.delete(id);
    			req.setAttribute("id", id);
			}
			return Result.success("system.success");
		} catch (Exception e) {
			return Result.error("system.error");
		}
    }


    @At("/detail/?")
    @Ok("beetl:/private/app/app_shopping_carts/detail.html")
    @RequiresAuthentication
	public Object detail(String id) {
		if (!Strings.isBlank(id)) {
			return appShoppingCartService.fetch(Integer.parseInt(id));

		}
		return null;
    }

}

package nuoshang.bluejay.modules.app.models;

import nuoshang.bluejay.common.base.Model;
import org.nutz.dao.entity.annotation.*;

import java.io.Serializable;
/**
 * 购物车
 * yuhaiming
 *
 * @time 2016-09-08 15:18:16
 */
@Table("app_shopping_cart")
public class App_shopping_cart extends Model implements Serializable{
    private static final long serialVersionUID = 1L;
    /********** attribute ***********/
    //购物车类(id, productId, productNum, typeId(型号类别), proPrice, userId,typeImgUrl)
    /****购物车id ****/
    @Id
    @Column("cart_id")
    private Long cart_id;

    @Column
    @Comment("用户ID")
    private Long userId;

    @Column("productId")
    @Comment("商品ID")
    private Long productId;

    @Column("productNum")
    @Comment("商品数量")
    private int productNum;

    @Column("typeId")
    @Comment("型号类别")
    private String typeId;

    @Column("typeImgUrl")
    @Comment("型号图片")
    @ColDefine(type = ColType.VARCHAR, width = 255)
    private String typeImgUrl;

    @Column
    @Comment("商品价格")
    private double proPrice;

    public Long getCart_id() {
        return cart_id;
    }

    public void setCart_id(Long cart_id) {
        this.cart_id = cart_id;
    }

    public Long getUserId() {
        return userId;
    }

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

    public Long getProductId() {
        return productId;
    }

    public void setProductId(Long productId) {
        this.productId = productId;
    }

    public int getProductNum() {
        return productNum;
    }

    public void setProductNum(int productNum) {
        this.productNum = productNum;
    }

    public String getTypeId() {
        return typeId;
    }

    public void setTypeId(String typeId) {
        this.typeId = typeId;
    }

    public String getTypeImgUrl() {
        return typeImgUrl;
    }

    public void setTypeImgUrl(String typeImgUrl) {
        this.typeImgUrl = typeImgUrl;
    }

    public double getProPrice() {
        return proPrice;
    }

    public void setProPrice(double proPrice) {
        this.proPrice = proPrice;
    }
}

3 回复
@SLog(tag = "修改App_shopping_cart", msg = "ID:${args[0].id}")

@Table("app_shopping_cart")
public class App_shopping_cart extends Model implements Serializable{
    private static final long serialVersionUID = 1L;
    /********** attribute ***********/
    //购物车类(id, productId, productNum, typeId(型号类别), proPrice, userId,typeImgUrl)
    /****购物车id ****/
    @Id
    @Column("cart_id")
    private Long cart_id;

SLog中的msg写的是取第一个参数(App_shopping_car)的id属性, 但App_shopping_cart只有cart_id属性,没有id属性. 这里说的id属性, 是名字叫id的java属性,与@Id无关.

PS: 为啥不统一命名呢? 每个类的主键名都不一样,这样真的好吗?

已找到错误
@At
@Ok("json")
@SLog(tag = "修改App_shopping_cart", msg = "ID:${args[0].cart_id}")
public Object editDo(@Param("..") App_shopping_cart appShoppingCart, HttpServletRequest req) {
try {

       appShoppingCart.setOpAt((int) (System.currentTimeMillis() / 1000));
       appShoppingCartService.updateIgnoreNull(appShoppingCart);
       return Result.success("system.success");
    } catch (Exception e) {
       return Result.error("system.error");
    }
}
添加回复
请先登陆
回到顶部