📄 createuserandroles.java
字号:
package com.heyang;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.heyang.domain.Role;
import com.heyang.domain.User;
import com.heyang.service.UserService;
/**
* 此类专用于创建用户及其拥有的角色
* @author 何杨
* @version 1.00
* @since 2009-1-5 上午11:12:17
*
*/
public class CreateUserAndRoles{
public static void main(String[] args){
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
UserService userService=(UserService)ctx.getBean("userService");
User zhangsan=new User("张三");
zhangsan.getRoles().add(new Role("添加"));
zhangsan.getRoles().add(new Role("修改"));
zhangsan.getRoles().add(new Role("删除"));
User lisi=new User("李四");
lisi.getRoles().add(new Role("添加"));
lisi.getRoles().add(new Role("修改"));
User wangwu=new User("王五");
wangwu.getRoles().add(new Role("添加"));
User zhaoliu=new User("赵六");
userService.create(zhangsan);
userService.create(lisi);
userService.create(wangwu);
userService.create(zhaoliu);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -