coding
yu0312chao的gravatar头像
yu0312chao2015-01-15 12:24:04

springMVC注解与hibernate完美结合完成基本的增删改查demo源码下载

   本项目适合于初学springMVC的朋友来完成的!注解方式是给项目带来的简单的操作性与适用性!如果项目中有啥改进的地方希望各位尽管说来!本人一定改正!由于jar包过大只给了一部分,找不到jar包随时找我要!

   对于本项目编程工具是Eclipse,数据库是Mysql,用了hibernate+springMVC框架来完成的!

工程的基本展示图:

springMVC注解与hibernate完美结合完成基本的增删改查demo源码下载

由于项目的代码量过大,我就只展示控制层Controller的代码:

/**
 * 南阳理工软件学院运动网平台<BR>
 * net.nyist.springmvc02.controller<BR>
 * HomeController.java<BR>
 * 创建人:yuchao <BR>时间:2015-1-13-下午5:29:31<BR> 
 * 版权个人所有
 */
package net.nyist.springmvc04.controller;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import net.nyist.springmvc04.domain.Person;
import net.nyist.springmvc04.service.IPersonService;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * 
 * HomeController<BR>
 * 创建人:yuchao <BR>
 * 时间:2015-1-13-下午5:29:31 <BR>
 * @version 1.0.0
 * 
 */
@Controller
@RequestMapping(value="/person")
public class PersonController {
    
	@Resource(name="personService")
	private IPersonService personService;
	@RequestMapping(value="/save")
	public String savePerson(){
		 
		Person person =new Person();
		person.setName("yuchao");
		person.setAddress("河南南阳");
		personService.savePerson(person);
		return "save";
	}
	
	@RequestMapping(value="/findAllPerson")
	public String findAllPerson(Map<String,Object> person){
		 
		List<Person> persons =personService.findAllPerson();
		person.put("persons",  persons);
		return "personList";
	}
	@RequestMapping(value="/delete")
	public String deletePerson(@RequestParam(value="id") String id,Person person){
		 
		Person person2 =new Person();
		person2.setId(id);
		personService.deletePerson(person2);
		return "redirect:/person/findAllPerson";
	}
	@RequestMapping(value="/deletes")
	public String deleteCheckedPerson(@RequestParam(value="allIds") String id){
		 
		String ids =id.substring(0,id.length()-1);
		String allIds[] =ids.split(",");
		Person person =new Person();
		for (int i = 0; i < allIds.length; i++) {
			person.setId(allIds[i]);
			personService.deletePerson(person);
		}
		
		return "redirect:/person/findAllPerson";
	}
	@RequestMapping(value="/updatePerson")
	public String updatePerson(@RequestParam(value="id") String id,Map<String, Person> person){
		 
		Person person2 =personService.findPersonById(id);
		person.put("person", person2);
		return "updatePersonForm";
	}
	@RequestMapping(value="/update")
	public String update(Person person) {

		personService.updatePerson(person);
		return "redirect:/person/findAllPerson";
	}
}

运行结果图:

springMVC注解与hibernate完美结合完成基本的增删改查demo源码下载


打赏

文件名:springmvcandhibernate.zip,文件大小:6295.196K下载
顶部客服微信二维码底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友