日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

Java中SSM框架實(shí)現(xiàn)增刪改查功能代碼詳解

瀏覽:21日期:2022-08-28 15:24:28

記錄一下自己第一次整合smm框架的步驟。

參考博客和網(wǎng)站有:我沒(méi)有三顆心臟 How2J學(xué)習(xí)網(wǎng)站

1.數(shù)據(jù)庫(kù)使用的是mySql,首先創(chuàng)建數(shù)據(jù)庫(kù)ssm1,并創(chuàng)建表student

create database ssm1;use ssm1; CREATE TABLE student( id int(11) NOT NULL AUTO_INCREMENT, student_id int(11) NOT NULL UNIQUE, name varchar(255) NOT NULL, age int(11) NOT NULL, sex varchar(255) NOT NULL, birthday date DEFAULT NULL, PRIMARY KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=utf8;

2.新建java web項(xiàng)目,命名為ssm1,并且導(dǎo)入相關(guān)的jar包。

3.建立pojo類,在這里命名為student,包名為com.ssm1.pojo

package com.ssm1.pojo;public class Student { private int id; private int student_id; private String name; private int age; private String sex; private String birthday; public int getId() { return id; } public void setId(int id) { this.id = id; } public int getStudent_id() { return student_id; } public void setStudent_id(int student_id) { this.student_id = student_id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } public String getBirthday() { return birthday; } public void setBirthday(String birthday) { this.birthday = birthday; }}

4.建立映射器接口studentMapper,包名為com.ssm1.mapper

package com.ssm1.mapper;import java.util.List;import com.ssm1.pojo.Student;public interface StudentMapper { public int add(Student student); public void delete(int id); public Student get(int id); public int update(Student student); public List<Student> list();}

5.建立與studentMapper對(duì)應(yīng)的xml文件,同樣屬于包c(diǎn)om.ssm1.mapper

<?xml version='1.0' encoding='UTF-8'?><!DOCTYPE mapper PUBLIC '-//mybatis.org//DTD Mapper 3.0//EN' 'http://mybatis.org/dtd/mybatis-3-mapper.dtd'><mapper namespace='com.ssm1.mapper.StudentMapper'> <insert parameterType='Student'> INSERT INTO student VALUES(#{student_id},#{name}, #{age}, #{sex}, #{birthday}) </insert> <!-- <insert parameterType='com.ssm1.pojo.Student' useGeneratedKeys='true' keyProperty='id'> insert into student <trim prefix='(' suffix=')' suffixOverrides=',' > <if test='student_id!=null'> student_id, </if> <if test='name!=null and name!=’’'> name, </if> <if test='age!=null'> age, </if> <if test='sex!=null and sex!=’’'> sex, </if> <if test='birthday!=null and birthday !=’’'> birthday, </if> </trim> <trim prefix='values (' suffix=')' suffixOverrides=',' > <if test='student_id!=null'> #{student_id}, </if> <if test='name!=null and name!=’’'> #{name}, </if> <if test='age!=null'> #{age}, </if> <if test='sex!=null and sex!=’’'> #{sex}, </if> <if test='birthday!=null and birthday !=’’'> #{birthday}, </if> </trim> </insert> --> <delete parameterType='Student'> delete from student where id= #{id} </delete> <select parameterType='_int' resultType='Student'> select * from student where id= #{id} </select> <update parameterType='Student'> UPDATE student SET student_id = #{student_id}, name = #{name}, age = #{age}, sex = #{sex}, birthday = #{birthday} WHERE id = #{id} </update> <select resultType='Student'> select * from student </select></mapper>

6.建立studentService接口,包名為com.ssm1.service

package com.ssm1.service;import java.util.List;import com.ssm1.pojo.Student;public interface StudentService { List<Student> list(); void add(Student s); void delete(Student s); void update(Student s); Student get(int id);}

7.建立studentServiceImpl類,實(shí)現(xiàn)接口,包名為com.ssm1.service

package com.ssm1.service;import java.util.List;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service;import com.ssm1.mapper.StudentMapper;import com.ssm1.pojo.Student;@Servicepublic class StudentServiceImpl implements StudentService { @Autowired StudentMapper studentMapper; @Override public List<Student> list() { // TODO Auto-generated method stub return studentMapper.list(); } @Override public void add(Student s) { // TODO Auto-generated method stub studentMapper.add(s); } @Override public void delete(Student s) { // TODO Auto-generated method stub studentMapper.delete(s.getId()); } @Override public void update(Student s) { // TODO Auto-generated method stub studentMapper.update(s); } @Override public Student get(int id) { // TODO Auto-generated method stub return studentMapper.get(id); }}

8.建立studentController控制器,包名為com.ssm1.controller

package com.ssm1.controller;import java.util.List;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.servlet.ModelAndView;import com.github.pagehelper.PageHelper;import com.github.pagehelper.PageInfo;import com.ssm1.pojo.Student;import com.ssm1.service.StudentService;import com.ssm1.util.Page;@Controller@RequestMapping('')public class StudentController { @Autowired StudentService studentService; @RequestMapping('/index') public ModelAndView index(Page page) { ModelAndView mav = new ModelAndView(); List<Student> cs = studentService.list(); mav.addObject('cs', cs); mav.setViewName('index'); return mav; } @RequestMapping(value = 'addStudent', produces = 'text/html; charset=utf-8') // @RequestMapping('addStudent') public ModelAndView addStudent(Student student) { studentService.add(student); ModelAndView mav = new ModelAndView('redirect:/index'); return mav; } @RequestMapping('deleteStudent') public ModelAndView deleteStudent(Student student) { studentService.delete(student); ModelAndView mav = new ModelAndView('redirect:/index'); return mav; } @RequestMapping('editStudent') public ModelAndView editStudent(Student student) { Student s=studentService.get(student.getId()); ModelAndView mav=new ModelAndView('editStudent'); mav.addObject('s',s); return mav; } @RequestMapping('updateStudent') public ModelAndView updateStudent(Student student) { studentService.update(student); ModelAndView mav=new ModelAndView('redirect:/index'); return mav; }}

9.在WEB-INF目錄下建立web.xml

<?xml version='1.0' encoding='UTF-8'?><web-app xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns='http://java.sun.com/xml/ns/javaee' xmlns:web='http://java.sun.com/xml/ns/javaee' xsi:schemaLocation='http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd' version='2.5'> <!-- spring的配置文件--> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- spring mvc核心:分發(fā)servlet --> <servlet> <servlet-name>mvc-dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!-- spring mvc的配置文件 --> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:springMVC.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>mvc-dispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <filter> <filter-name>CharacterEncodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>utf-8</param-value> </init-param> </filter> <filter-mapping> <filter-name>CharacterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping></web-app>

10.在src目錄下新建applicationContext.xml文件,這是Spring的配置文件

<?xml version='1.0' encoding='UTF-8'?><beans xmlns='http://www.springframework.org/schema/beans' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:aop='http://www.springframework.org/schema/aop' xmlns:tx='http://www.springframework.org/schema/tx' xmlns:jdbc='http://www.springframework.org/schema/jdbc' xmlns:context='http://www.springframework.org/schema/context' xmlns:mvc='http://www.springframework.org/schema/mvc' xsi:schemaLocation=' http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd'><!-- 配置@Service包的掃描 --> <context:annotation-config /> <context:component-scan base-package='com.ssm1.service' /> <!-- 配置數(shù)據(jù)庫(kù)的連接 --> <bean class='org.springframework.jdbc.datasource.DriverManagerDataSource'> <property name='driverClassName'> <value>com.mysql.jdbc.Driver</value> </property> <property name='url'> <value>jdbc:mysql://localhost:3306/ssm1?characterEncoding=UTF-8</value> </property> <property name='username'> <value>root</value> </property> <property name='password'> <value>admin</value> </property> </bean> <!-- 配置SQLSessionFactory --> <bean class='org.mybatis.spring.SqlSessionFactoryBean'> <property name='typeAliasesPackage' value='com.ssm1.pojo' /> <property name='dataSource' ref='dataSource'/> <property name='mapperLocations' value='classpath:com/ssm1/mapper/*.xml'/> </bean> <bean class='org.mybatis.spring.mapper.MapperScannerConfigurer'> <property name='basePackage' value='com.ssm1.mapper'/> </bean></beans>

11.在src目錄下新增springMVC.xml文件

<?xml version='1.0' encoding='UTF-8'?><beans xmlns='http://www.springframework.org/schema/beans' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:aop='http://www.springframework.org/schema/aop' xmlns:tx='http://www.springframework.org/schema/tx' xmlns:jdbc='http://www.springframework.org/schema/jdbc' xmlns:context='http://www.springframework.org/schema/context' xmlns:mvc='http://www.springframework.org/schema/mvc' xsi:schemaLocation='http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd'><context:annotation-config/> <context:component-scan base-package='com.ssm1.controller'> <context:include-filter type='annotation' expression='org.springframework.stereotype.Controller'/> </context:component-scan> <mvc:annotation-driven /> <mvc:default-servlet-handler /> <bean class='org.springframework.web.servlet.view.InternalResourceViewResolver'> <property name='viewClass' value='org.springframework.web.servlet.view.JstlView' /> <property name='prefix' value='/WEB-INF/jsp/' /> <property name='suffix' value='.jsp' /> </bean></beans>

12.在WEB-INF下創(chuàng)建jsp目錄,并創(chuàng)建文件index.jsp和editStudent.jsp

<%@ page language='java' contentType='text/html; charset=UTF-8' pageEncoding='UTF-8' import='java.util.*'%><%@ taglib uri='http://java.sun.com/jsp/jstl/core' prefix='c'%><!DOCTYPE html><html><head><meta charset='UTF-8'><title>Insert title here</title></head><body> <table align=’center’ border=’1’ cellspacing=’0’> <tr> <td>id</td> <td>student_id</td> <td>name</td> <td>age</td> <td>sex</td> <td>birthday</td> <td>編輯</td> <td>刪除</td> </tr> <c:forEach items='${cs}' var='c' varStatus='st'> <tr> <td>${c.id}</td> <td>${c.student_id}</td> <td>${c.name}</td> <td>${c.age}</td> <td>${c.sex}</td> <td>${c.birthday}</td> <td><a href='http://www.b3g6.com/bcjs/editStudent?id=${c.id}' rel='external nofollow' >編輯</a></td> <td><a href='http://www.b3g6.com/bcjs/deleteStudent?id=${c.id}' rel='external nofollow' >刪除</a></td> </tr> </c:forEach></table> <div style='text-align:center;margin-top:40px'> <form method='post' action='addStudent' > 學(xué)生學(xué)號(hào): <input name='student_id' value='' type='text'> <br><br> 學(xué)生姓名: <input name='name' value='' type='text'> <br><br> 學(xué)生年紀(jì): <input name='age' value='' type='text'> <br><br> 學(xué)生性別: <input name='sex' value='' type='text'> <br><br> 學(xué)生生日: <input name='birthday' value='' type='text'> <br><br> <input type='submit' value='增加學(xué)生'> </form> </div> <div style='text-align:center; margin-top:20px'> <form action='${pageContext.request.contextPath }/index' method='post'> <input value='刷新' type='submit'> </form> </div></body></html>

<%@ page language='java' contentType='text/html; charset=UTF-8' pageEncoding='UTF-8' import='java.util.*'%><%@ taglib uri='http://java.sun.com/jsp/jstl/core' prefix='s'%> <div style='width:500px;margin:0px auto;text-align:center'> <div style='text-align:center;margin-top:40px'> <form method='post' action='updateStudent'> 分類名稱: <input name='student_id' value='${s.student_id}' type='text'> <br><br> 分類名稱: <input name='name' value='${s.name}' type='text'> <br><br> 分類名稱: <input name='age' value='${s.age}' type='text'> <br><br> 分類名稱: <input name='sex' value='${s.sex}' type='text'> <br><br> 分類名稱: <input name='birthday' value='${s.birthday}' type='text'> <br><br> <input type='hidden' value='${s.id}' name='id'> <input type='submit' value='修改分類'> </form> </div> </div>

13.最后在tomcat上部署項(xiàng)目,輸入路徑localhost:端口號(hào)/ssm1/index即可訪問(wèn)

到此這篇關(guān)于Java中SSM框架實(shí)現(xiàn)增刪改查功能代碼詳解的文章就介紹到這了,更多相關(guān)SSM框架實(shí)現(xiàn)增刪改查功內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: Java
相關(guān)文章:
日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区
亚洲欧美久久| 欧美一级专区| 亚洲青青久久| 韩国三级一区| 综合亚洲色图| 免费在线小视频| 亚洲九九精品| 日韩理论片av| 天堂久久一区| 久久国产直播| 国产精品一区高清| 久久久一二三| 欧美日韩黄网站| 在线视频观看日韩| 日本欧美在线| 欧美在线资源| 日韩午夜av在线| 不卡av一区二区| 免费一级欧美片在线观看网站| 91成人网在线观看| 国产精品乱战久久久| 偷拍精品精品一区二区三区| 日韩一区二区三区免费视频| 精品资源在线| 日韩综合精品| 蜜桃视频在线网站| 国产一区二区三区探花| 欧美va亚洲va日韩∨a综合色| 欧美手机在线| 欧美综合精品| 午夜电影亚洲| 亚洲www免费| 国产极品模特精品一二| aa国产精品| 国产精品字幕| 久久亚洲黄色| 蜜桃久久av| 亚洲专区欧美专区| 亚洲深深色噜噜狠狠爱网站 | 亚洲激情偷拍| 丁香婷婷久久| 日韩在线观看不卡| 国产综合色产| 国产夫妻在线| 久久国产精品99国产| 亚洲国产专区校园欧美| 日韩av一级| 久久在线视频免费观看| 国产一区二区三区四区二区 | 久久国产三级| 久久免费精品| 99久久99久久精品国产片果冰| 欧美69视频| 1000部精品久久久久久久久| 亚洲精品影视| 日韩成人免费| 亚洲欧美高清| 老牛国内精品亚洲成av人片| 久久国产免费| 欧美一级久久| 日韩一区自拍| 日本中文字幕不卡| 国产aⅴ精品一区二区四区| 日本精品不卡| 日韩一二三区在线观看| 亚洲天堂av资源在线观看| 久久中文字幕导航| 五月婷婷六月综合| 免费人成网站在线观看欧美高清| 电影91久久久| 日韩影片在线观看| 国产一区导航| 国产a亚洲精品| 青草国产精品| 蜜桃av一区二区| 精品捆绑调教一区二区三区| 日韩av在线播放中文字幕| 麻豆成全视频免费观看在线看| 日本成人在线视频网站| 蘑菇福利视频一区播放| 久久视频精品| 欧美国产极品| 欧美影院视频| 国产精品美女| 伊人久久大香线蕉av超碰演员| 国产精品亚洲欧美日韩一区在线| 91久久国产| 国产成人精品免费视| 国产精品久av福利在线观看| 亚洲欧美日韩高清在线| 999久久久国产精品| 婷婷激情久久| 欧美日韩国产欧| 亚洲人成高清| 麻豆成人91精品二区三区| 国内一区二区三区| 亚洲成人va| 中文字幕日本一区二区| 亚洲综合日韩| 欧美精品aa| 久久精品123| 日韩中出av| 美女视频免费精品| 国产二区精品| 欧美日韩一视频区二区| 色偷偷色偷偷色偷偷在线视频| 亚洲天堂黄色| 视频一区中文字幕精品| 国产精品va视频| aa亚洲婷婷| 欧美激情三区| 久久精品在线| 国产乱子精品一区二区在线观看 | 日本a级不卡| 久久国产精品99国产| 国产精品99免费看| 正在播放日韩精品| 国产精品15p| 中文字幕一区二区三区四区久久| 日韩在线精品| 日韩欧美一区二区三区在线视频| 久久久久伊人| 日韩av在线播放中文字幕| 日韩中文字幕区一区有砖一区 | 日韩一区欧美| 国产精品久久免费视频| 午夜精品久久久久久久久久蜜桃| 日韩午夜av在线| 精品久久精品| 亚洲激精日韩激精欧美精品| 日本久久一区| 国产亚洲欧美日韩精品一区二区三区 | 蜜桃国内精品久久久久软件9| 日韩午夜一区| 粉嫩av一区二区三区四区五区| 欧美好骚综合网| 天堂成人国产精品一区| 国产精品麻豆成人av电影艾秋 | 日韩精品免费观看视频| 国产麻豆一区二区三区精品视频| 国产欧美精品| 中文字幕在线免费观看视频| 欧美亚洲激情| 日韩一区二区三免费高清在线观看| 国产亚洲欧美日韩在线观看一区二区| 国模精品一区| 手机精品视频在线观看| 日韩一区二区在线免费| 亚洲综合日韩| 性欧美xxxx免费岛国不卡电影| 国产伊人久久| 久久精品99久久久| 亚洲美女久久精品| 午夜影院欧美| 欧美国产美女| 久久精品五月| 午夜欧美精品| 青青草伊人久久| 久久蜜桃av| 欧美日韩免费观看视频| 石原莉奈在线亚洲二区| 欧美日韩国产传媒| 日韩福利视频导航| 国产精品1luya在线播放| 一区在线视频观看| 国产欧美日韩一区二区三区在线| 粉嫩av一区二区三区四区五区| 九九九精品视频| 国产欧美一区二区三区精品观看| 欧美午夜不卡| 日韩精品视频一区二区三区| 精品亚洲精品| 蜜臀va亚洲va欧美va天堂| 亚洲一级淫片| 久久久久国产| 亚洲欧美久久久| 亚洲激情另类| 国产综合精品一区| 久久精品资源| 欧美日韩国产免费观看 | 国产精品1区| 欧美激情精品| 日本不卡一区二区三区| 国产成人精品999在线观看| 精品美女视频 | 欧美激情另类| 久久亚洲精精品中文字幕| 亚洲精品大片| 日韩三级视频| 亚洲在线成人| 你懂的国产精品永久在线| 蜜桃久久久久久| 日本视频中文字幕一区二区三区| 欧美成人精品午夜一区二区| 视频小说一区二区| 午夜日本精品| 五月精品视频| 国产精品老牛| 综合亚洲自拍| 国产一区二区久久久久|