`
sb33060418
  • 浏览: 152286 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

spring mvc(五)CRUD及PUT/DELETE参数

阅读更多
使用springmvc实现基于页面的增删改查,只要对Controller不同方法返回不同的的View(页面或json/xml)即可。
本节示例对Teacher集合进行CRUD的操作。

1.设计
设计Teacher模块前台需要一个页面进行列表展示和交互,通过ajax异步提交form并返回json结果;后台需要提供查询列表、创建、删除、修改、查询等方法。考虑到分页需求,还需要一个统计总数方法。
地址请求方法说明
/teacherGET模块入口,返回jsp
/teacher/listGET查询teacher集合
/teacher/countGET查询teacher数量
/teacher/getGET根据id查询某个teacher
/teacher/savePOST创建新teacher,content中包含资源内容
/teacher/updatePOST更新teacher,content中包含资源内容
/resource/removeGET根据id删除teacher

2.Teacher POJO、DAO、SERVICE
在com.sunbin.test.teacher包下创建POJO、DAO、SERVICE。
Teacher类:
package com.sunbin.test.teacher.pojo;

import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "Teacher")
public class Teacher {

	private int id;
	private int age;
	private String name;

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Override
	public String toString() {
		return "Teacher [id=" + id + ", age=" + age + ", name=" + name + "]";
	}
}

@XmlRootElement(name = "Teacher")注解使得Teacher类可以被转换成xml/json格式输出。
TeacherService接口:
package com.sunbin.test.teacher.service;

import java.util.List;

import com.sunbin.test.teacher.pojo.Teacher;

public interface TeacherService {

	@SuppressWarnings("rawtypes")
	public List list();

	public int count();

	public void save(Teacher teacher);

	public void remove(Teacher teacher);

	public void update(Teacher teacher);

	public Teacher get(Teacher teacher);

}

定义了6个服务层抽象方法:查询列表、统计总数、创建、删除、修改、查询。
TeacherDao接口:
package com.sunbin.test.teacher.dao;

import java.util.List;

import com.sunbin.test.teacher.pojo.Teacher;

public interface TeacherDao {

	@SuppressWarnings("rawtypes")
	public List list();

	public int count();

	public void save(Teacher teacher);

	public void remove(Teacher teacher);

	public void update(Teacher teacher);

	public Teacher get(Teacher teacher);

}

定义了与service接口对应的6个数据层抽象方法。

3.接口实现
示例中不使用数据库,而是使用一个List来存储Teacher集合。
TeacherDaoImpl数据层接口实现:
package com.sunbin.test.teacher.dao.impl;

import java.util.ArrayList;
import java.util.List;
import org.springframework.stereotype.Repository;

import com.sunbin.test.teacher.dao.TeacherDao;
import com.sunbin.test.teacher.pojo.Teacher;

@Repository("teacherDao")
public class TeacherDaoImpl implements TeacherDao {

	private static List<Teacher> teachers = new ArrayList<Teacher>();

	@SuppressWarnings("rawtypes")
	@Override
	public List list() {
		System.out.println("TeacherDaoImpl.list:" + teachers);
		return teachers;
	}

	@Override
	public int count() {
		System.out.println("TeacherDaoImpl.count:" + teachers.size());
		return teachers.size();
	}

	@Override
	public void save(Teacher teacher) {
		System.out.println("TeacherDaoImpl.save:" + teacher);
		int teacherId = 1;
		if (teachers.size() > 0) {
			teacherId = teachers.get(teachers.size() - 1).getId() + 1;
		}
		teacher.setId(teacherId);
		teachers.add(teacher);
	}

	@Override
	public void remove(Teacher teacher) {
		System.out.println("TeacherDaoImpl.remove:" + teacher);
		int teacherId = teacher.getId();
		for (int i = 0; i < teachers.size(); i++) {
			Teacher teacherI = teachers.get(i);
			if (teacherI.getId() == teacherId) {
				teachers.remove(i);
				return;
			}
		}
	}

	@Override
	public void update(Teacher teacher) {
		System.out.println("TeacherDaoImpl.update:" + teacher);
		int teacherId = teacher.getId();
		for (int i = 0; i < teachers.size(); i++) {
			Teacher teacherI = teachers.get(i);
			if (teacherI.getId() == teacherId) {
				teachers.remove(i);
				teachers.add(i, teacher);
				return;
			}
		}
	}

	@Override
	public Teacher get(Teacher teacher) {
		System.out.println("TeacherDaoImpl.get:" + teacher);
		int teacherId = teacher.getId();
		for (int i = 0; i < teachers.size(); i++) {
			Teacher teacherI = teachers.get(i);
			if (teacherI.getId() == teacherId) {
				return teacherI;
			}
		}
		return null;
	}

}

该类实现了数据层接口,且@Repository("teacherDao")注解声明一个名为teacherDao的数据层Bean。
TeacherServiceImpl服务层接口实现:
package com.sunbin.test.teacher.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sunbin.test.teacher.dao.TeacherDao;
import com.sunbin.test.teacher.pojo.Teacher;
import com.sunbin.test.teacher.service.TeacherService;

@Service("teacherService")
public class TeacherServiceImpl implements TeacherService {

	@Autowired
	private TeacherDao teacherDao;

	@SuppressWarnings("rawtypes")
	@Override
	public List list() {
		System.out.println("TeacherServiceImpl.list");
		return teacherDao.list();
	}

	@Override
	public int count() {
		System.out.println("TeacherServiceImpl.count");
		return teacherDao.count();
	}

	@Override
	public void save(Teacher teacher) {
		System.out.println("TeacherServiceImpl.save:" + teacher);
		teacherDao.save(teacher);
	}

	@Override
	public void remove(Teacher teacher) {
		System.out.println("TeacherServiceImpl.remove:" + teacher);
		teacherDao.remove(teacher);
	}

	@Override
	public void update(Teacher teacher) {
		System.out.println("TeacherServiceImpl.update:" + teacher);
		teacherDao.update(teacher);
	}

	@Override
	public Teacher get(Teacher teacher) {
		System.out.println("TeacherServiceImpl.get:" + teacher);
		return teacherDao.get(teacher);
	}

}

该类实现了服务层接口,且@Service("teacherService")注解声明一个名为teacherService的服务层Bean,@Autowired注解将注入teacherDao bean。

4.Contoller
Conroller需要实现设计的7个方法:
package com.sunbin.test.teacher.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.json.MappingJackson2JsonView;
import org.springframework.stereotype.Controller;
import org.springframework.beans.factory.annotation.Autowired;

import com.sunbin.test.teacher.pojo.Teacher;
import com.sunbin.test.teacher.service.TeacherService;

@Controller
@RequestMapping("/teacher")
public class TeacherController {

	@Autowired
	private TeacherService teacherService;

	@RequestMapping("")
	public ModelAndView index(HttpServletRequest arg0, HttpServletResponse arg1)
			throws Exception {
		ModelAndView modelAndView = new ModelAndView("teacher/index");
		return modelAndView;
	}

	@RequestMapping("/list")
	public ModelAndView list(HttpServletRequest arg0, HttpServletResponse arg1)
			throws Exception {
		ModelAndView modelAndView = new ModelAndView(
				new MappingJackson2JsonView());
		modelAndView.addObject("list", teacherService.list());
		return modelAndView;
	}

	@RequestMapping("/count")
	public ModelAndView count(HttpServletRequest arg0, HttpServletResponse arg1)
			throws Exception {
		ModelAndView modelAndView = new ModelAndView(
				new MappingJackson2JsonView());
		modelAndView.addObject("count", teacherService.count());
		return modelAndView;
	}

	@RequestMapping(value = "/save", method = { RequestMethod.POST })
	public ModelAndView save(Teacher teacher, HttpServletRequest arg0,
			HttpServletResponse arg1) throws Exception {
		ModelAndView modelAndView = new ModelAndView(
				new MappingJackson2JsonView());
		teacherService.save(teacher);
		modelAndView.addObject("status", "y");
		return modelAndView;
	}

	@RequestMapping("/remove")
	public ModelAndView remove(Teacher teacher, HttpServletRequest arg0,
			HttpServletResponse arg1) throws Exception {
		ModelAndView modelAndView = new ModelAndView(
				new MappingJackson2JsonView());
		teacherService.remove(teacher);
		modelAndView.addObject("status", "y");
		return modelAndView;
	}

	@RequestMapping(value = "/update", method = { RequestMethod.POST })
	public ModelAndView update(Teacher teacher, HttpServletRequest arg0,
			HttpServletResponse arg1) throws Exception {
		ModelAndView modelAndView = new ModelAndView(
				new MappingJackson2JsonView());
		teacherService.update(teacher);
		modelAndView.addObject("status", "y");
		return modelAndView;
	}

	@RequestMapping("/get")
	public ModelAndView get(Teacher teacher, HttpServletRequest arg0,
			HttpServletResponse arg1) throws Exception {
		ModelAndView modelAndView = new ModelAndView(
				new MappingJackson2JsonView());
		modelAndView.addObject("teacher", teacherService.get(teacher));
		return modelAndView;
	}

}

除了首页使用teacher/index.jsp展示,其他接口返回MappingJackson2JsonView。
save和update配置了method = { RequestMethod.POST },必须使用POST方法访问。
Controller中的方法可以使用Teacher作为参数,springmvc自动将页面输入组装成pojo传入后台。

5.首页
在WEB-INF/jsp/teacher/下创建index.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>teacher</title>
	<script type="text/javascript" src="<%=path %>/resources/js/jquery-3.2.0.js"></script>
	<script type="text/javascript">
		$(document).ready(function(){
			list();
			var ajaxOption = null;
			$("#saveButton").click(function(){
				save();
			});
		});
		function list(){
			$.ajax({
				url:"teacher/list",
				dataType:"json",
				success:function(data){
					$("#listBody").empty();
					$.each(data.list, function(i, item){
						var teacherTr = "<tr><form name='updateForm_"+item.id+"' action='teacher/update' method='POST'>"
							+"<td><input type='hidden' name='id' id='id_"+item.id+"' value='"+item.id+"'/>"+item.id+"</td>"
							+"<td><input type='text' name='name' id='name_"+item.id+"' value='"+item.name+"' /></td>"
							+"<td><input type='text' name='age' id='age_"+item.id+"' value='"+item.age+"' /></td>"
							+"<td><a href='javascript:void(0);' onclick='get("+item.id+");'>get</a> "
							+"<a href='javascript:void(0);' onclick='remove("+item.id+");'>remove</a> "
							+"<input type='submit' value='update' id='updateButton_"+item.id+"' onclick='update("+item.id+");' /></td></tr>";
							//alert(teacherTr);
						$("#listBody").append(teacherTr);
					});
					count();
				}
			});
		}
		function count(){
			$.ajax({
				url:"teacher/count",
				dataType:"json",
				success:function(data){
					$("#count").html(data.count);
				}
			});
		}
		function save(){
			$("#saveButton").attr("disabled", true);
			$.ajax({
				url:"teacher/save",
				type:"POST",
				data:"name="+$("#name").val()+"&"+"age="+$("#age").val(),
				dataType:"json",
				complete:function(){
					$("#saveButton").attr("disabled", false);
				},
				success:function(data){
					alert(data.status);
					list();
				}
			});
		}
		function get(id){
			$.ajax({
				url:"teacher/get",
				data:"id="+id,
				dataType:"json",
				success:function(data){
					var teacherInfo = "id:"+data.teacher.id+"\nname:"+data.teacher.name+"\nage:"+data.teacher.age;
					alert(teacherInfo);
				}
			});
		}
		function remove(id){
			$.ajax({
				url:"teacher/remove",
				data:"id="+id,
				dataType:"json",
				success:function(data){
					alert(data.status);
					list();
				}
			});
		}
		function update(id){
			$("#updateButton_"+id).attr("disabled", true);
			$.ajax({
				url:"teacher/update",
				type:"POST",
				data:"id="+id+"&name="+$("#name_"+id).val()+"&"+"age="+$("#age_"+id).val(),
				dataType:"json",
				complete:function(data){
					$("#updateButton_"+id).attr("disabled", false);
				},
				success:function(data){
					alert(data.status);
					list();
				}
			});
		}
	</script>
</head>
<body>
	save
	<form name="saveForm" action="teacher/save" method="POST">
		name:<input type="text" name="name" id="name" /> 
		
 
		age:<input type="text" name="age" id="age" /> 
		
 
		<input type="button" value="save" id="saveButton" />
	</form>
	count:<span id="count"></span>
	<br/>
	list
	<table border="1">
		<thead>
			<tr>
				<td>id</td>
				<td>name</td>
				<td>age</td>
				<td>操作</td>
			</tr>
		</thead>
		<tbody id="listBody">
		</tbody>
	</table>
</body>
</html>

list()方法GET teacher/list,对返回的teacher集合使用表格展示,并调用count()更改统计数量。
count()方法GET teacher/count,显示返回数量。
save()方法将数据POST至teacher/save保存,成功后刷新表格。
get(id)方法GET teacher/get,弹窗显示单条记录。
remove(id)方法GET teacher/remove,删除单挑记录,成功后刷新表格。
update(id)方法将数据POST至teacher/save更新,成功后刷新表格。

6.测试
重新部署至tomcat,访问http://localhost:8080/testRest/teacher
可看到页面内容,并进行增删改查操作


7.springmvc PUT/DELETE调用及参数的坑
如果想要支持http的PUT和DELETE方法,实现RESTFUL接口,只需将Controller方法的注解改为PUT/DELETE:
@RequestMapping(value = "/update", method = { RequestMethod.PUT })

可以使用ajax直接调用PUT请求:
$.ajax({
	url:"teacher/update",
	type:"PUT",
	data:"id="+id+"&name="+$("#name_"+id).val()+"&"+"age="+$("#age_"+id).val(),
...

如果通过表单form调用就没这么简单了。因为html的form只支持GET、POST方法,不能直接发送PUT、DELETE请求。springmvc为了解决这个问题,增加了特殊的过滤器。
在web.xml中增加配置:
<filter>  
    <filter-name>HttpMethodFilter</filter-name>  
    <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>  
</filter>  
<filter-mapping>  
    <filter-name>HttpMethodFilter</filter-name>  
    <servlet-name>spring</servlet-name>  
</filter-mapping>

配置拦截器处理隐藏参数。HiddenHttpMethodFilter主要源码如下:
public class HiddenHttpMethodFilter extends OncePerRequestFilter {

	/** Default method parameter: {@code _method} */
	public static final String DEFAULT_METHOD_PARAM = "_method";

	private String methodParam = DEFAULT_METHOD_PARAM;


	/**
	 * Set the parameter name to look for HTTP methods.
	 * @see #DEFAULT_METHOD_PARAM
	 */
	public void setMethodParam(String methodParam) {
		Assert.hasText(methodParam, "'methodParam' must not be empty");
		this.methodParam = methodParam;
	}

	@Override
	protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
			throws ServletException, IOException {

		String paramValue = request.getParameter(this.methodParam);
		if ("POST".equals(request.getMethod()) && StringUtils.hasLength(paramValue)) {
			String method = paramValue.toUpperCase(Locale.ENGLISH);
			HttpServletRequest wrapper = new HttpMethodRequestWrapper(request, method);
			filterChain.doFilter(wrapper, response);
		}
		else {
			filterChain.doFilter(request, response);
		}
	}

拦截器会处理POST请求中的_method参数,转换为PUT/DELETE请求。
修改页面form,增加_method参数:
<form action="..." method="POST">
	<input type="hidden" name="_method" value="PUT">
	...
</form>

这种配置虽然能调用到PUT/DELETE,但是参数传递会出现问题,因为springmvc的HiddenHttpMethodFilter不能组装参数成pojo。增加以下拦截器:
<filter>  
    <filter-name>HttpMethodFilter</filter-name>  
    <filter-class>org.springframework.web.filter.HttpPutFormContentFilter</filter-class>  
</filter>  
<filter-mapping>  
    <filter-name>HttpMethodFilter</filter-name>  
    <servlet-name>spring</servlet-name>  
</filter-mapping>

查看HttpPutFormContentFilter拦截器源码,可以看到是对PUT请求的contentbody进行处理。
	@Override
	protected void doFilterInternal(final HttpServletRequest request, HttpServletResponse response,
			FilterChain filterChain) throws ServletException, IOException {

		if (("PUT".equals(request.getMethod()) || "PATCH".equals(request.getMethod())) && isFormContentType(request)) {
			HttpInputMessage inputMessage = new ServletServerHttpRequest(request) {
				@Override
				public InputStream getBody() throws IOException {
					return request.getInputStream();
				}
			};
			MultiValueMap<String, String> formParameters = formConverter.read(null, inputMessage);
			HttpServletRequest wrapper = new HttpPutFormContentRequestWrapper(request, formParameters);
			filterChain.doFilter(wrapper, response);
		}
		else {
			filterChain.doFilter(request, response);
		}
	}

两种方法都可以发送PUT请求调用/update。

该拦截器只能处理PUT的contentbody。
对于DELETE请求,不能获取通过body提交的内容,只能使用参数或者地址变量。
POST content:
function remove(id){
	$.ajax({
		url:"teacher/remove",
		type:"POST",
		data:"id="+id,

修改为DELETE请求参数:
function remove(id){
	$.ajax({
		url:"teacher/remove?id="+id,
		type:"DELETE",

Controller方法:
	@RequestMapping(value = "/remove", method = { RequestMethod.DELETE })
	public ModelAndView remove(Integer id,
			HttpServletRequest arg0, HttpServletResponse arg1) throws Exception {
		ModelAndView modelAndView = new ModelAndView(
				new MappingJackson2JsonView());
		Teacher teacher = new Teacher();
		teacher.setId(id);
		teacherService.remove(teacher);
		modelAndView.addObject("status", "y");
		return modelAndView;
	}

通过ajax发送DELETE请求调用/remove地址成功。
同样可以使用form隐藏参数:
<form action="..." method="POST">
	<input type="hidden" name="_method" value="DELETE">
	...
</form>
  • 大小: 18 KB
0
0
分享到:
评论

相关推荐

    第四部分、Spring MVC完成CRUD.rar

    在本资源"第四部分、Spring MVC完成CRUD.rar"中,我们主要探讨的是Spring MVC框架在实际项目开发中的应用,特别是在实现CRUD(创建、读取、更新、删除)操作中的详细过程。Spring MVC是Java Web开发中常用的一个模块...

    一个完整的Spring MVC的CRUD操作实例

    在这个完整的Spring MVC CRUD操作实例中,我们将深入探讨如何使用Spring MVC实现创建(Create)、读取(Retrieve)、更新(Update)和删除(Delete)数据的基本功能。 首先,让我们从项目结构开始。一个典型的Spring MVC...

    spring mvc+jquery easyui CRUD

    在本项目中,我们主要探讨的是如何利用Spring MVC框架与jQuery EasyUI库来实现一个基本的CRUD(创建、读取、更新、删除)功能。Spring MVC是Java平台上的一个强大的MVC(Model-View-Controller)框架,它提供了一个...

    Spring MVC Cookbook(PACKT,2016).pdf

    7. **RESTful服务**:创建符合REST原则的URL结构,使用HTTP动词(GET、POST、PUT、DELETE)来实现CRUD操作,并使用JSON或XML进行数据交换。 8. **异常处理**:了解如何自定义异常处理器,以及使用@ControllerAdvice...

    Spring MVC--6.RESTful SpringMVC CRUD

    RESTful SpringMVC CRUD是指使用RESTful原则设计Spring MVC应用程序,以执行创建(Create)、读取(Retrieve)、更新(Update)和删除(Delete)数据的基本操作。 首先,我们需要理解REST(Representational State Transfer...

    Spring MVC--7.REST风格 CRUD

    在本教程中,我们将深入探讨Spring MVC框架如何支持RESTful(Representational State Transfer)风格的CRUD(创建、读取、更新和删除)操作。REST是一种软件架构风格,广泛应用于Web服务设计,它强调资源的识别和...

    spring-mvc的增删改查(crud)的实现

    在本文中,我们将深入探讨如何利用Spring MVC实现CRUD(创建、读取、更新和删除)操作,并了解如何处理静态资源以及在MyEclipse环境中部署和运行项目。 **1. RESTful风格的CRUD** REST(Representational State ...

    springmvc实现crud及图片上传.zip

    在本项目 "springmvc实现crud及图片上传.zip" 中,我们将探讨如何利用 Spring MVC 实现 CRUD 操作以及图片上传功能。 CRUD(Create, Read, Update, Delete)是数据库操作的基本动作,代表创建、读取、更新和删除。...

    spring mvc 搭建依赖包

    Spring MVC也支持创建RESTful Web服务,通过@RequestMapping的HTTP方法参数(GET、POST、PUT、DELETE等),可以轻松构建符合REST原则的API。 10. **Spring Data JPA 和 MyBatis集成** 虽然Spring JDBC提供了一层...

    对应Spring MVC 的博客

    - 使用HTTP方法(GET、POST、PUT、DELETE)对应资源的CRUD操作。 9. **Spring MVC与其他Spring模块集成**: - 与Spring AOP结合,实现面向切面编程。 - 与Spring Security集成,实现权限控制。 - 结合Spring ...

    spring mvc 注解实例

    在这个注解实例中,我们将深入探讨Spring MVC中的核心注解以及如何利用它们实现对数据库表的增删改查(CRUD)操作。拦截器是Spring MVC中的另一个重要概念,它允许我们在请求处理前后执行自定义逻辑。 首先,让我们...

    Spring MVC+SimpleJdbcDaoSupport增删改查小例子

    **Spring MVC + SimpleJdbcDaoSupport 增删改查小例子详解** Spring MVC 是一个广泛使用的Java Web框架,用于构建高效、灵活的Web应用程序。它提供了模型-视图-控制器(MVC)架构,使得开发者可以将业务逻辑、数据...

    spring-rest.rar_DEMO_employeeDS.java_rest spring mvc_spring mvc_

    在本示例中,我们将深入探讨如何利用Spring MVC框架构建RESTful API,主要涉及`employeeDS.java`这个可能的数据服务类以及与`rest_spring_mvc`、`spring_mvc`和`spring_rest`相关的概念。`spring-rest.rar`是一个...

    Spring-MVC-Hibernate-CRUD-源码.rar

    这是一个关于使用Spring MVC和Hibernate框架实现CRUD操作的源代码示例。CRUD代表创建(Create)、读取(Retrieve)、更新(Update)和删除(Delete),是数据库操作的基本功能。Spring MVC作为Spring框架的一部分,是用于...

    springmvc之restful风格CRUD

    本文将深入探讨如何在Spring MVC中实现RESTful风格的CRUD操作,这对初学者尤其有价值。 首先,了解REST(Representational State Transfer,表述性状态转移)是一种网络应用程序的设计风格和开发方式,基于HTTP协议...

    spring mvc 使用教程

    Spring MVC 支持 PUT 和 DELETE 请求,通过 `@PutMapping` 和 `@DeleteMapping` 注解。确保在服务器和客户端都正确配置了这些请求类型。 7. **Session 和 Request 作用域** 在 Spring MVC 中,我们可以使用 `...

    spring MVC morphia mongo 整合的例子

    7. **RESTful API设计**:示例可能展示了如何使用Spring MVC创建RESTful API,通过HTTP方法(GET, POST, PUT, DELETE)来对应MongoDB的操作。 8. **错误处理和日志记录**:Spring MVC提供了异常处理机制,可以定制...

    Spring MVC-API(5)

    在本篇中,我们将深入探讨Spring MVC框架中的API设计与使用,主要针对"Spring MVC-API(5)"这一主题展开。Spring MVC是Spring框架的一部分,它提供了一个模型-视图-控制器(MVC)架构来构建Web应用程序。API在软件...

    spring mvc学习代码

    9. **RESTful API设计**:Spring MVC鼓励遵循RESTful原则设计URL,通过HTTP方法(GET、POST、PUT、DELETE)来对应资源的CRUD操作。使用@RequestMapping注解来映射URL路径和HTTP方法。 10. **单元测试和整合测试**:...

    spring mvc beginner guider -source code

    8. **Spring MVC与Spring Data JPA集成**:介绍如何结合使用Spring MVC和Spring Data JPA进行数据库操作,包括Repository接口的定义和使用,以及数据的CRUD操作。 9. **单元测试与整合测试**:了解如何编写JUnit...

Global site tag (gtag.js) - Google Analytics