使用ssm+maven+bootstrap+mysql实现增删改查的一个小demo

目录

一.运行效果

二,新建mavenProject

三,详细代码

web.xml

springmvc.xml

db.properties

applicationContext_mapper.xml

applicationContext_service.xml

applicationContext_transaction.xml

ItemInfo.java

ItemController.java

ItemMapper.java

ItemMapper.xml

ItemService.java

ItemServicelmpl.java

item_list.jsp

四,运行。右键项目-【run as】-【maven build...】

五,MySQL数据库文件

六,完整项目下载


此项目和这个项目都能实现同样的功能,但是这个项目是maven project,那个项目是dynamic web project

这里需要maven的基础:https://blog.csdn.net/qq_40323256/article/details/90168191

ssm的基础:https://blog.csdn.net/qq_40323256/article/details/89791744

bootstrap的基础:https://blog.csdn.net/qq_40323256/article/details/91490905

MySQL的基础:https://blog.csdn.net/qq_40323256/article/details/82905734

一.运行效果

先来看一下最终运行效果使用ssm+maven+bootstrap+mysql实现增删改查的一个小demo_第1张图片

 

二,新建mavenProject

注意:

1,选择war包。

2,通常新建的maven项目会报错,这是因为没有web.xml,解决此报错很简单,直接在项目上右键【Java EE Tools】-【generate deployment xxx】,然后就不报错了

先看下目录

使用ssm+maven+bootstrap+mysql实现增删改查的一个小demo_第2张图片

三,详细代码

用maven的好处之一就是不用到处找jar包,想要什么jar包直接在pom.xml里面添加依赖就可以了。想要依赖可以去中央仓库

我们可以把常用的依赖收集起来,以后可以直接复制pom.xml,省时省力

pom.xml


  4.0.0
  com.lijiang
  ssm_spring_mvc_maven
  0.0.1-SNAPSHOT
  war
  ssm_spring_mvc_maven
  用maven做的ssm_spring_mvc项目
  
  
  	
  	5.0.8.RELEASE
  	3.4.6
  	1.3.2
  	5.1.46
  	12.1.0.2.0
  	1.0.16
  	1.0
  	1.6.4.RELEASE
  	1.1.1
  	1.2
  	1.2.16
  	1.6.1
  	1.6.4
  	1.3.1
  	2.9.6
  	4.9
  	8.0.53
  	8.0.53
  	
  	0.9.5.2
  	
  	
  	3.8.0
  	2.2
  
  
  
  
  	
  		 
		
		    org.springframework
		    spring-core
		    ${spring.version}
		
	 	
		   org.springframework
		   spring-web
		   ${spring.version}
	    
	    
		   org.springframework
		   spring-tx
		   ${spring.version}
	    
	    
		   org.springframework
		   spring-jdbc
		   ${spring.version}
	    
	    
		   org.springframework
		   spring-webmvc
		   ${spring.version}
	    
	    
		   org.springframework
		   spring-aop
		   ${spring.version}
	    
	    
		   org.springframework
		   spring-context-support
		   ${spring.version}
	    
	    
		   org.springframework
		   spring-test
		   ${spring.version}
	    
	    
	    
	     
		
		    org.mybatis
		    mybatis
		    ${mybais.version}
		
		
		
		    org.mybatis
		    mybatis-spring
		    ${mybatis-spring.version}
		
		
		
		
		    com.fasterxml.jackson.core
		    jackson-core
		    ${jackson.version}
		
		
		    com.fasterxml.jackson.core
		    jackson-annotations
		    ${jackson.version}
		
		
		    com.fasterxml.jackson.core
		    jackson-databind
		    ${jackson.version}
		
		
		

		
		    com.mchange
		    c3p0
		    ${c3p0.version}
		
  	
  
  
  
  
    
	
	    org.springframework
	    spring-core
	
 	
	   org.springframework
	   spring-web
    
    
	   org.springframework
	   spring-tx
    
    
	   org.springframework
	   spring-jdbc
    
    
	   org.springframework
	   spring-webmvc
    
    
	   org.springframework
	   spring-aop
    
    
	   org.springframework
	   spring-context-support
    
    
	   org.springframework
	   spring-test
    
    
        
    
	
	    org.mybatis
	    mybatis
	
	
	
	
	    org.mybatis
	    mybatis-spring
	
 
	
	
	    mysql
	    mysql-connector-java
	    ${mysql-connector.version}
	
 
	
	    cn.easyproject
	    ojdbc7
	    ${ojdbc7.version}
	
	
	
	 
	
	    com.alibaba
	    druid
	    ${druid.version}
	
	
	
	
	    aopalliance
	    aopalliance
	    ${aopalliance.version}
	
	
	
	    org.aspectj
	    com.springsource.org.aspectj.weaver
	    ${aspectj.weaver.version}
	
	
	
	
	
	    org.apache.commons
	    com.springsource.org.apache.commons.logging
	    ${commons.logging.version}
	
 
	
	
		javax.servlet
		jstl
		${jstl.version}
	
	
	
	
		log4j
		log4j
		${log4j.version}
	
	
		org.slf4j
		slf4j-api
		${slf4j-api.version}
	
	
		org.slf4j
		slf4j-nop
		${slf4j-nop.version}
	
	
 
	
	  
		commons-fileupload  
		commons-fileupload  
		${fileupload.version}  
	
	
	
	
	    com.fasterxml.jackson.core
	    jackson-core
	
	
	    com.fasterxml.jackson.core
	    jackson-annotations
	
	
	    com.fasterxml.jackson.core
	    jackson-databind
	
	
	
	
	
	    junit
	    junit
	    ${junit.version}
	    test
	
	
	
	
  		org.apache.tomcat
  		tomcat-servlet-api
  		${servlet-api.version}
  		provided
  	
	
	
	    org.apache.tomcat
	    tomcat-jsp-api
	    ${jsp-api.version}
	    provided
	
	
	
		
		    com.mchange
		    c3p0
		    ${c3p0.version}
		
	
  
  
  
  	
  		
  			org.apache.maven.plugins
  			maven-compiler-plugin
  			${maven-compiler-plugin.version}
  			
  				1.8
				1.8  			
  			
  		
  		
  		
  			org.apache.tomcat.maven
  			tomcat7-maven-plugin
  			${tomcat7-maven-plugin.version}
  			
  				UTF-8
  				http://localhost:8080/manager/text
  				lijiang
  				111
  			
  		
  		
  	
  	
  	
    
		
			src/main/java
			
				**/*.properties
				**/*.xml
			
			false
		
		
		
			src/main/resources
			
				**/*.properties
				**/*.xml
			
			false
		
	
  
  

web.xml



  ssm_spring_mvc_maven
  
    index.html
    index.htm
    index.jsp
    default.html
    default.htm
    default.jsp
  
  
  
     
  
  	default
  	*.css
  	*.ttf
  	*.woff
  	*.js
  	*.png
  	*.jpg
  	*.gif
  
  
  
    
  
  	encoding
  	org.springframework.web.filter.CharacterEncodingFilter
  	
  		encoding
  		utf-8
  	
  
  
  	encoding
  	
  	/*
  
  
  
  
    
  
  	springmvc
  	org.springframework.web.servlet.DispatcherServlet
  	
  		
  		contextConfigLocation
  		classpath:springmvc.xml
  	
  
  
  	springmvc
  	
  	/
  
  
  
  
  
  	org.springframework.web.context.ContextLoaderListener
  
  
  	contextConfigLocation
  	classpath:applicationContext_*.xml
  

springmvc.xml



		
		
		
		
		
		
		
		
		
		
			
			
		
		
		
		

db.properties

jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.jdbcUrl=jdbc:mysql://localhost:3306/ssm
jdbc.username=root
jdbc.password=root

applicationContext_mapper.xml



		
				
		
		
		
		
			
			
			
			
		
		
		
		
			
			
		
		
		
		
			
		

applicationContext_service.xml



		
		

applicationContext_transaction.xml



				
		
			
		
		
				
		

ItemInfo.java

package com.lijiang.bean;

public class ItemInfo {

	//id
	private Integer id;
	//username
	private String username;
	private String password;
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}

	public ItemInfo(Integer id, String username, String password) {
		super();
		this.id = id;
		this.username = username;
		this.password = password;
	}

	
	
}

ItemController.java

package com.lijiang.controller;

import java.util.ArrayList;
import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.lijiang.bean.ItemInfo;
import com.lijiang.service.ItemService;

@Controller
@RequestMapping("/admin/items")
public class ItemController {

	@Autowired
	private ItemService itemService;
	
//	显示所有列表
	@RequestMapping("allList.do")
	public String selectAll(Model model,ItemInfo itemInfo){
		List itemList=itemService.selectAll(itemInfo);

		model.addAttribute("itemList", itemList);
		return "item_list";
	}
	
//	删除
	@RequestMapping("delete.do")
	public String delete(Integer id){
		itemService.deleteById(id);
		return "forward:allList.do";
	}
	
//	添加
	@RequestMapping("save.do")
	public String save(ItemInfo itemInfo){
		itemService.saveItem(itemInfo);
		return "forward:allList.do";
	}
	
//	修改
	@RequestMapping("update.do")
    public String update(ItemInfo itemInfo){
    	itemService.updateItem(itemInfo);
    	return "forward:allList.do";
    }
	
//	编辑 回显数据
	@RequestMapping("edit.do")
	@ResponseBody
	public ItemInfo edit(Integer id) {
		return itemService.selectItemInfoById(id);
	}

}

ItemMapper.java

package com.lijiang.mapper;

import java.util.List;

import com.lijiang.bean.ItemInfo;

public interface ItemMapper {

	List selectAll(ItemInfo itemInfo);

	void deleteById(Integer id);

	void saveItem(ItemInfo itemInfo);

	void updateItem(ItemInfo itemInfo);

	ItemInfo selectItemInfoById(Integer id);

}

ItemMapper.xml







  

  
   delete from user where id=#{id}
  

   
   insert into user values(#{id},#{username}, #{password});
   

   
   	update user
  		
  			username = #{username},
  			password = #{password}
  		
  		where id = #{id}
   

	

ItemService.java

package com.lijiang.service;

import java.util.List;

import com.lijiang.bean.ItemInfo;

public interface ItemService {

	List selectAll(ItemInfo itemInfo);

	void deleteById(Integer id);

	void saveItem(ItemInfo itemInfo);

	void updateItem(ItemInfo itemInfo);

	ItemInfo selectItemInfoById(Integer id);

}

ItemServicelmpl.java

package com.lijiang.service;

import java.util.List;

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

import com.lijiang.bean.ItemInfo;
import com.lijiang.mapper.ItemMapper;

@Service
public class ItemServicelmpl implements ItemService {

	@Autowired
	private ItemMapper itemMapper;

	public List selectAll(ItemInfo itemInfo) {
		return itemMapper.selectAll(itemInfo);
	}

	public void deleteById(Integer id) {
		itemMapper.deleteById(id);
	}

	public void saveItem(ItemInfo itemInfo) {
		itemMapper.saveItem(itemInfo);
	}

	public void updateItem(ItemInfo itemInfo) {
		itemMapper.updateItem(itemInfo);
	}

	public ItemInfo selectItemInfoById(Integer id) {
		return itemMapper.selectItemInfoById(id);
	}

}

item_list.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>




Insert title here









            
		
  
id username password
${item.id} ${item.username} ${item.password}

 

四,运行。右键项目-【run as】-【maven build...】

右键项目-【run as】-【maven build...】,在Goals中输入:clean tomcat7:run,如果不能运行,就用:tomcat7:run

第一次运行maven项目时输入clean tomcat7:run,后面就用  clean tomcat7:redeploy 

使用ssm+maven+bootstrap+mysql实现增删改查的一个小demo_第3张图片

五,MySQL数据库文件

使用ssm+maven+bootstrap+mysql实现增删改查的一个小demo_第4张图片使用ssm+maven+bootstrap+mysql实现增删改查的一个小demo_第5张图片

六,完整项目下载

CSDN下载:https://download.csdn.net/download/qq_40323256/11242993

GitHub下载:https://github.com/LiJiangJiangJiang/ssm_spring_mvc_maven

你可能感兴趣的:(SSM,Maven,maven,ssm,bootstrap)