这是代码:
public Response getABC(Request request) throws Exception {
Response res = new Response();
try {
if (request.someProperty == 1) {
// business logic
} else {
throw new Exception("xxxx");
}
} catch (Exception e) {
res.setMessage(e.getMessage); // I think this is weird
}
return res;
}
Run Code Online (Sandbox Code Playgroud)
这个程序运行正常.我认为它应该重新设计,但如何?
当我使用spring框架编写业务代码时,我总是使用单例作用域并避免使用原型作用域。我认为原型和单例之间存在性能差异。由于原型范围的原因,spring 每次调用都会创建一个新实例。我认为它比使用单例作用域慢。我对吗?我是否对性能考虑太多?
我创建了一个函数“ addroute()”来动态添加路由,但是它不起作用(路由器未更改)。这是使用addRoutes方法的正确方法吗?我从教程中学到了这一点。如果没有,那么给我一个正确的例子,谢谢!
...
const Bar={
template:'#panels',
data(){
return {title:'badss'}
}
};
const Foo={
template:"#panels",
data(){
return {title:'hell'}
}
};
const router = new VueRouter({
routes:[
{path:'/foo',component:Foo},
{path:'/bar',component:Bar}
]
});
new Vue({
el:'#root',
router:router,
data:{
stats:stats
},
methods: {
//
},
});
function addroute(){//watch here
router.addRoutes([{path:'/ioio',component:{template:'#panels'}}])
}
setInterval("addroute()", 2000)//watch here
...
Run Code Online (Sandbox Code Playgroud) 当我使用spring框架时,我发现应该提取的东西,例如,服务组件(或自动装配的成员变量)。代码显示如下:
abstract class Payment {
PaymentService paymentService;
void setPaymentService(OrderPaymentService paymentService) {
this.paymentService = paymentService;
}
}
@Component
public class CancelPayment extends Payment{
private OtherService2 otherSerivce2;
@Autowired
@Override
public void setPaymentService(PaymentService paymentService) {
super.setPaymentService(paymentService);
}
@Autowired
public CancelPayment(OtherService2 s2) {
this.otherSerivce2 = s2;
}
}
@Component
public class CreatePayment extends Payment{
private OtherService1 otherSerivce1;
@Autowired
@Override
public void setPaymentService(PaymentService paymentService) {
super.setPaymentService(paymentService);
}
@Autowired
public CreatePayment (OtherService1 s1) {
this.otherSerivce1 = s1;
}
}
Run Code Online (Sandbox Code Playgroud)
如您所见,我在每个子类中都使用了setter注入。这是比自动装配其父母的成员变量更好的做法吗?
java ×3
spring ×2
ecmascript-6 ×1
exception ×1
if-statement ×1
javascript ×1
throw ×1
vue-router ×1
vue.js ×1