当前位置: 首页>>代码示例>>Java>>正文


Java Path类代码示例

本文整理汇总了Java中br.com.caelum.vraptor.Path的典型用法代码示例。如果您正苦于以下问题:Java Path类的具体用法?Java Path怎么用?Java Path使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Path类属于br.com.caelum.vraptor包,在下文中一共展示了Path类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: profile

import br.com.caelum.vraptor.Path; //导入依赖的package包/类
/**
 * Shows the profile of some user
 * @param userId the user to show
 */
@Path("/profile/{userId}")
public void profile(int userId) {
	if (!this.userSession.getRoleManager().getCanViewProfile()) {
		this.result.redirectTo(MessageController.class).accessDenied();
	}
	else {
		User userToEdit = this.userRepository.get(userId);
		this.result.include("user", userToEdit);
		this.result.include("userTotalTopics", this.userRepository.getTotalTopics(userId));
		this.result.include("rankings", this.rankingRepository.getAllRankings());
		this.result.include("isAnonymousUser", userId == this.config.getInt(ConfigKeys.ANONYMOUS_USER_ID));

		boolean canEdit = userSession.getRoleManager().getCanEditUser(userToEdit, userSession.getUser().getGroups());
		this.result.include("canEdit", canEdit);
	}
}
 
开发者ID:eclipse123,项目名称:JForum,代码行数:21,代码来源:UserController.java

示例2: getURIsFor

import br.com.caelum.vraptor.Path; //导入依赖的package包/类
@Override
protected String[] getURIsFor(Method javaMethod, Class<?> type) {
	if (javaMethod.isAnnotationPresent(RuntimePath.class) && javaMethod.isAnnotationPresent(Path.class)) {
		Path pathAnn = javaMethod.getAnnotation(Path.class);
		RuntimePath runtimePathAnn = javaMethod.getAnnotation(RuntimePath.class);
		
		RuntimeRouteResolver resolve;
		String[] uris = pathAnn.value();
		try {
			resolve = runtimePathAnn.value().newInstance();
			uris = resolve.resolve(javaMethod, type, uris);
		} catch (InstantiationException | IllegalAccessException e) {
			LOG.errorf(e, "Error instantiating runtime path resolver.");
			checkArgument(false, "Error instantiating runtime path resolver.");
		}

		checkArgument(uris.length > 0, "You must specify at least one path on @Path at %s", javaMethod);
		checkArgument(getUris(javaMethod).length == 0,
				"You should specify paths either in @Path(\"/path\") or @Get(\"/path\") (or @Post, @Put, @Delete), not both at %s", javaMethod);

		fixURIs(type, uris);
		return uris;
	}
	return super.getURIsFor(javaMethod, type);
}
 
开发者ID:progolden,项目名称:vraptor-boilerplate,代码行数:26,代码来源:RuntimeRouteParser.java

示例3: loadEmprestimosLivros

import br.com.caelum.vraptor.Path; //导入依赖的package包/类
@Path("/emprestimo/loadEmprestimosLivros")
public void loadEmprestimosLivros(Usuario u){
	
	List listObjs = emprestimoDAO.getLivrosEmprestimo(u.getId());
	
	List<Livro> list = new ArrayList<Livro>();
	for (Object o : listObjs) {

		Livro l = (Livro) o;
		list.add(l);
		//System.out.println(l.getTitulo());
	}
	
	result.use(json()).from(list, "livros")
	.serialize();
}
 
开发者ID:lucasaquiles,项目名称:saci-biblio-service,代码行数:17,代码来源:EmprestimoController.java

示例4: listar

import br.com.caelum.vraptor.Path; //导入依赖的package包/类
@Get
@Path("listar")
public void listar() {
	List<Especialidade> especialidades = null;

	try {
		especialidades = especialidadeApplication.listar();
	} catch (MaternidadeException e) {
		e.printStackTrace();
		validator
				.add(new ValidationMessage(e.getMessage(), "especialidade"));
	}

	validator.onErrorUsePageOf(EspecialidadeController.class).inicio();
	result.include("especialidades", especialidades);
}
 
开发者ID:aldaypinheiro,项目名称:maternidade,代码行数:17,代码来源:EspecialidadeController.java

示例5: gerarContas

import br.com.caelum.vraptor.Path; //导入依赖的package包/类
@Path("/gerar")
public void gerarContas() {
	Random random = new Random();
	char c = 65;
	for (int i = 0; i < 25; i++) {
		String numero = "" + c  + (random.nextInt(1000));
		Conta conta = new Conta(numero, "" + random.nextInt(10000));
		System.out.println("Adicionando conta " + i);
		for(int a = 0; a < 4; a++) {
			Transacao transacao = conta.novaTranscacao(
					new BigDecimal(random.nextDouble()*10000), 
					Tipo.values()[random.nextInt(2)], 
					new GregorianCalendar(random.nextInt(6)+2006, random.nextInt(12), random.nextInt(29)));
			session.persist(transacao);
		}
		session.persist(conta);
		c++;
		
	}
	result.include("mensagem", "Contas geradas!");
}
 
开发者ID:tiarebalbi,项目名称:caelum-fj91-projeto,代码行数:22,代码来源:ContasController.java

示例6: geraRelatorioHibernateCursor

import br.com.caelum.vraptor.Path; //导入依赖的package包/类
@Path("/hibernate-cursor")
public void geraRelatorioHibernateCursor() throws IOException{
	long antes = System.currentTimeMillis();
	ScrollableResults results = sessionFactory.openStatelessSession().createCriteria(Transacao.class).setMaxResults(QTD_REGISTROS).scroll();
	System.out.printf("Pesquisa feita em %dms%n", System.currentTimeMillis()-antes);
	PrintWriter writer = response.getWriter();
	SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
	int i=0;
	while(results.next()){
		if(i++%20000==0){
			System.out.println(i);
		}
		Transacao t = (Transacao) results.get()[0];
		writer.write(t.toFile(dateFormat)+"\n");
	}
	writer.close();
	result.use(Results.nothing());
	System.out.println(System.currentTimeMillis()-antes+" milisegundos");
}
 
开发者ID:tiarebalbi,项目名称:caelum-fj91-projeto,代码行数:20,代码来源:RelatorioDeTransacoesController.java

示例7: geraRelatorioHibernatePuro

import br.com.caelum.vraptor.Path; //导入依赖的package包/类
@Path("/hibernate-puro")
public void geraRelatorioHibernatePuro() throws IOException{
	long antes = System.currentTimeMillis();
	List<Transacao> list = session.createCriteria(Transacao.class).setMaxResults(200000).list();
	System.out.printf("Pesquisa feita em %dms%n", System.currentTimeMillis()-antes);
	PrintWriter writer = response.getWriter();
	SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
	int i=0;
	for (Transacao transacao : list) {
		if(i++%20000==0){
			System.out.println(i);
		}
		writer.write(transacao.toFile(dateFormat)+"\n");
	}
	writer.close();
	result.use(Results.nothing());
	System.out.println(System.currentTimeMillis()-antes+" milisegundos");
}
 
开发者ID:tiarebalbi,项目名称:caelum-fj91-projeto,代码行数:19,代码来源:RelatorioDeTransacoesController.java

示例8: editar

import br.com.caelum.vraptor.Path; //导入依赖的package包/类
@Get
@Path("editar/{id:[0-9]{1,15}}")
public void editar(Integer id) {
	Especialidade especialidade = null;

	try {
		especialidade = especialidadeApplication.buscarPorId(id);
	} catch (MaternidadeException e) {
		validator
				.add(new ValidationMessage(e.getMessage(), "Especialidade"));
		e.printStackTrace();
	}

	validator.onErrorUsePageOf(EspecialidadeController.class).listar();
	result.include("especialidade", especialidade);
}
 
开发者ID:aldaypinheiro,项目名称:maternidade,代码行数:17,代码来源:EspecialidadeController.java

示例9: visualizar

import br.com.caelum.vraptor.Path; //导入依赖的package包/类
@Get
@Path("visualizar/{id:[0-9]{1,15}}")
public void visualizar(Integer id) {
	Especialidade especialidade = null;

	try {
		especialidade = especialidadeApplication.buscarPorId(id);
	} catch (MaternidadeException e) {
		validator
				.add(new ValidationMessage(e.getMessage(), "Especialidade"));
		e.printStackTrace();
	}

	validator.onErrorUsePageOf(EspecialidadeController.class).listar();
	result.include("especialidade", especialidade);
}
 
开发者ID:aldaypinheiro,项目名称:maternidade,代码行数:17,代码来源:EspecialidadeController.java

示例10: novo

import br.com.caelum.vraptor.Path; //导入依赖的package包/类
@Get
@Path("novo")
public void novo() {
	List<Medico> medicos = null;
	List<Enfermeiro> enfermeiros = null;

	try {
		medicos = medicoApplication.listar();
		enfermeiros = enfermeiroApplication.listar();
	} catch (MaternidadeException e) {
		validator.add(new ValidationMessage(e.getMessage(), "Bebê"));
		e.printStackTrace();
	}

	validator.onErrorForwardTo(BebeController.class).inicio();
	result.include("medicos", medicos);
	result.include("enfermeiros", enfermeiros);
}
 
开发者ID:aldaypinheiro,项目名称:maternidade,代码行数:19,代码来源:BebeController.java

示例11: addToMyList

import br.com.caelum.vraptor.Path; //导入依赖的package包/类
/**
    * Accepts HTTP PUT requests. <br>
    * 
    * <strong>URL:</strong> /users/login/musics/id (for example, 
    * /users/john/musics/3 adds the music with id 3 to the john's 
    * collection)<br>
    * 
    * <strong>View:</strong> redirects to user's home <br>
    *
    * You can use more than one variable on URI. Since the browsers 
    * don't support PUT method you have to pass an additional parameter: 
    * <strong>_method=PUT</strong> for calling this method.<br>
    *
    * This method adds a music to a user's collection.
    */
   @Path("/users/{user.login}/musics/{music.id}")
   @Put
public void addToMyList(User user, Music music) {
   	User currentUser = userInfo.getUser();
    userDao.refresh(currentUser);
    
    validator.check(user.getLogin().equals(currentUser.getLogin()), 
            new SimpleMessage("user", "you_cant_add_to_others_list"));

    validator.check(!currentUser.getMusics().contains(music), 
            new SimpleMessage("music", "you_already_have_this_music"));

	validator.onErrorUsePageOf(UsersController.class).home();

	music = musicDao.load(music);
	currentUser.add(music);
	
	result.redirectTo(UsersController.class).home();
}
 
开发者ID:caelum,项目名称:vraptor4,代码行数:35,代码来源:UsersController.java

示例12: apagar

import br.com.caelum.vraptor.Path; //导入依赖的package包/类
@Get
@Path("apagar/{id:[0-9]{1,15}}")
public void apagar(Integer id) {
	Especialidade esp = null;

	try {
		esp = especialidadeApplication.buscarPorId(id);
	} catch (MaternidadeException e) {
		validator
				.add(new ValidationMessage(e.getMessage(), "Especialidade"));
		e.printStackTrace();
	}

	especialidadeApplication.apagar(esp);

	validator.onErrorUsePageOf(EspecialidadeController.class).listar();
	result.redirectTo(EspecialidadeController.class).listar();
}
 
开发者ID:aldaypinheiro,项目名称:maternidade,代码行数:19,代码来源:EspecialidadeController.java

示例13: apagar

import br.com.caelum.vraptor.Path; //导入依赖的package包/类
@Get
@Path("apagar/{id:[0-9]{1,15}}")
public void apagar(Integer id) {
	Bebe bebe = null;

	try {
		bebe = bebeApplication.buscarPorId(id);
	} catch (MaternidadeException e) {
		validator.add(new ValidationMessage(e.getMessage(), "Bebê"));
		e.printStackTrace();
	}

	validator.onErrorUsePageOf(BebeController.class).listar();
	bebeApplication.apagar(bebe);
	result.redirectTo(BebeController.class).inicio();
}
 
开发者ID:aldaypinheiro,项目名称:maternidade,代码行数:17,代码来源:BebeController.java

示例14: shouldObeyPriorityOfRoutes

import br.com.caelum.vraptor.Path; //导入依赖的package包/类
@Test
public void shouldObeyPriorityOfRoutes() throws Exception {
	Route first = mock(Route.class);
	when(first.getControllerMethod()).thenReturn(anyControllerMethod());
	Route second = mock(Route.class);
	when(second.getControllerMethod()).thenReturn(anyControllerMethod());

	ControllerMethod method2 = second.controllerMethod(request, "second");

	router.add(second);
	router.add(first);

	when(first.getPriority()).thenReturn(Path.HIGH);
	when(second.getPriority()).thenReturn(Path.LOW);

	EnumSet<HttpMethod> get = EnumSet.of(HttpMethod.GET);
	when(first.allowedMethods()).thenReturn(get);
	when(second.allowedMethods()).thenReturn(get);

	when(first.canHandle(anyString())).thenReturn(false);
	when(second.canHandle(anyString())).thenReturn(true);

	ControllerMethod found = router.parse("anything", HttpMethod.GET, request);
	assertThat(found, is(method2));
}
 
开发者ID:caelum,项目名称:vraptor4,代码行数:26,代码来源:DefaultRouterTest.java

示例15: usesTheFirstRegisteredRuleMatchingThePattern

import br.com.caelum.vraptor.Path; //导入依赖的package包/类
@Test
public void usesTheFirstRegisteredRuleMatchingThePattern() throws SecurityException, NoSuchMethodException {
	Route route = mock(Route.class);
	Route second = mock(Route.class, "second");
	when(route.getControllerMethod()).thenReturn(anyControllerMethod());
	when(second.getControllerMethod()).thenReturn(anyControllerMethod());

	when(route.canHandle("/clients/add")).thenReturn(true);
	when(second.canHandle("/clients/add")).thenReturn(true);

	EnumSet<HttpMethod> all = EnumSet.allOf(HttpMethod.class);

	when(route.allowedMethods()).thenReturn(all);
	when(second.allowedMethods()).thenReturn(all);

	when(route.controllerMethod(request, "/clients/add")).thenReturn(method);
	when(route.getPriority()).thenReturn(Path.HIGHEST);
	when(second.getPriority()).thenReturn(Path.LOWEST);

	router.add(route);
	router.add(second);

	ControllerMethod found = router.parse("/clients/add", HttpMethod.POST, request);
	assertThat(found, is(equalTo(method)));
}
 
开发者ID:caelum,项目名称:vraptor4,代码行数:26,代码来源:DefaultRouterTest.java


注:本文中的br.com.caelum.vraptor.Path类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。