有一个基于JSP的项目我不是很懂,有没有求大神给个网站你懂的能帮我看一下?教教我

freemarker应用场景_freemarker+应用场景_壮志凌云
freemarker+应用场景
为青少年营造风清气正的网站,已过滤百度结果中的敏感描述
&&百度文库
语义关联近似词猜&正规性45地理位置网址标题|网址|摘要F0略略分类信息&|&猜&非正规中略略略精确匹配2略略分类信息&|&猜&非正规中略略略精确匹配3略略分类信息&|&猜&非正规中略略略精确匹配4略略分类信息&|&猜&非正规中略略略精确匹配5略略分类信息&|&猜&非正规中略略略精确匹配6略略分类信息&|&猜&非正规中略略略精确匹配7略略分类信息&|&猜&非正规中略略略精确匹配8略略分类信息&|&猜&非正规中略略略精确匹配9略略分类信息&|&猜&非正规中略略略精确匹配10
12时间限制猜&实时动态5相关检索词泛时效性8F1略略略略略略略略2略略略略略略略略3百度文库略略略略略略略4略略略略略略略略5略略略略略略略略6略略略略略略略略7略略略略略略略略8略略略略略略略略9略略略略略略略略10
url2345摘要前标题后标题F2略略略略略正文略2略略略略略略略3略略略略略正文略4略略略略略正文略5略略略略略正文略6略略略略略正文略7略略略略略正文略8略略略略略正文略9略略略略略正文略10
123原创猜&网址形式6相关词猜&相似度F3略略略略子页优先级较低略略精确匹配2略略略略子页优先级较低略召回精确匹配3略略略略子页优先级较低略召回精确匹配4略略略略子页优先级较低略略精确匹配5略略略略子页优先级较低略略精确匹配6略略略略主页次优先&|&子页内容充实略召回精确匹配7略略略略主页次优先&|&子页内容充实略略精确匹配8略略略略主页次优先&|&子页内容充实略召回精确匹配9略略略略主页次优先&|&子页内容充实略召回精确匹配10日志总数:123篇
评论总数:276条
分类总数:3个
标签总数:147个
友情链接:9个
网站运行:2007天
音乐随身听
现在位置: &&
&>&&>&正文
SpringMVC+Spring+MyBatis整合完整版Web实例(附数据)
最近段时间正在学习Spring MVC和MyBatis的一些知识。自己也在网络上面找了一些例子来练习。但是都不是很完整。所以,今天,自己也抽空写了个完成的关于Spring MVC + Spring + MyBatis(简称 SSM)的一个CRUD的完整Web 演示例子。如果你也是刚好学习这几个框架的新手,或许我做的这个例子对你刚好有所帮助哦!
演示工程的目录结构
添加数据页面
修改数据的页面
查询出的数据列表
下面来说下这个演示的小例子。首先,我是使用MyEclipse工具做的这个例子,整合了Sping 3 、Spring MVC 3 、MyBatis框架,演示数据库采用MySQL数据库。例子中主要操作包括对数据的添加(C)、查找(R)、更新(U)、删除(D)。我在这里采用的数据库连接池是来自阿里巴巴的Druid,至于Druid的强大之处,我在这里就不做过多的解释了,有兴趣的朋友们可以去网上谷歌或者百度一下哦!好了下面我就贴上这次这个演示例子的关键代码:
BaseController
BaseController.java
package com.bky.
import java.util.L
import java.util.UUID;
import javax.servlet.http.HttpServletR
import org.springframework.beans.factory.annotation.A
import org.springframework.stereotype.C
import org.springframework.web.bind.annotation.RequestM
import com.bky.model.A
import com.bky.service.BaseS
@Controller
public class BaseController {
private BaseService baseS
public BaseService getBaseService() {
return baseS
@Autowired
public void setBaseService(BaseService baseService) {
this.baseService = baseS
@SuppressWarnings("finally")
@RequestMapping("addInfo")
public String add(Add add,HttpServletRequest request){
add.setId(UUID.randomUUID().toString());
System.out.println(add.getId() + ":::::" + add.getTname() + ":::::" + add.getTpwd());
String str = baseService.addInfo(add);
System.out.println(str);
request.setAttribute("InfoMessage", str);
} catch (Exception e) {
e.printStackTrace();
request.setAttribute("InfoMessage", "添加信息失败!具体异常信息:" + e.getMessage());
} finally {
return "result";
@RequestMapping("getAll")
public String getAddInfoAll(HttpServletRequest request){
List&Add& list = baseService.getAll();
System.out.println(list);
request.setAttribute("addLists", list);
return "listAll";
} catch (Exception e) {
e.printStackTrace();
request.setAttribute("InfoMessage", "信息载入失败!具体异常信息:" + e.getMessage());
return "result";
@SuppressWarnings("finally")
@RequestMapping("del")
public String del(String tid,HttpServletRequest request){
String str = baseService.delete(tid);
request.setAttribute("InfoMessage", str);
} catch (Exception e) {
e.printStackTrace();
request.setAttribute("InfoMessage", "删除信息失败!具体异常信息:" + e.getMessage());
} finally {
return "result";
@RequestMapping("modify")
public String modify(String tid,HttpServletRequest request){
Add add = baseService.findById(tid);
request.setAttribute("add", add);
return "modify";
} catch (Exception e) {
e.printStackTrace();
request.setAttribute("InfoMessage", "信息载入失败!具体异常信息:" + e.getMessage());
return "result";
@SuppressWarnings("finally")
@RequestMapping("update")
public String update(Add add,HttpServletRequest request){
String str = baseService.update(add);
request.setAttribute("InfoMessage", str);
} catch (Exception e) {
e.printStackTrace();
request.setAttribute("InfoMessage", "更新信息失败!具体异常信息:" + e.getMessage());
} finally {
return "result";
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
package com.bky.controller;&import java.util.List;import java.util.UUID;&import javax.servlet.http.HttpServletRequest;&import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;&import com.bky.model.Add;import com.bky.service.BaseService;&@Controllerpublic class BaseController {&&&&&private BaseService baseService;&&&&&public BaseService getBaseService() {&&&&&&&&return baseService;&&&&}&&&&@Autowired&&&&public void setBaseService(BaseService baseService) {&&&&&&&&this.baseService = baseService;&&&&}&&&&&@SuppressWarnings("finally")&&&&@RequestMapping("addInfo")&&&&public String add(Add add,HttpServletRequest request){&&&&&&&&try {&&&&&&&&&&&&&&&&&&&&&&&&add.setId(UUID.randomUUID().toString());&&&&&&&&&&&&System.out.println(add.getId() + ":::::" + add.getTname() + ":::::" + add.getTpwd());&&&&&&&&&&&&String str = baseService.addInfo(add);&&&&&&&&&&&&System.out.println(str);&&&&&&&&&&&&request.setAttribute("InfoMessage", str);&&&&&&&&} catch (Exception e) {&&&&&&&&&&&&e.printStackTrace();&&&&&&&&&&&&request.setAttribute("InfoMessage", "添加信息失败!具体异常信息:" + e.getMessage());&&&&&&&&} finally {&&&&&&&&&&&&&&&&&&&&&&&&return "result";&&&&&&&&}&&&&}&&&&&@RequestMapping("getAll")&&&&public String getAddInfoAll(HttpServletRequest request){&&&&&&&&try {&&&&&&&&&&&&&&&&&&&&&&&&List&Add& list = baseService.getAll();&&&&&&&&&&&&System.out.println(list);&&&&&&&&&&&&request.setAttribute("addLists", list);&&&&&&&&&&&&return "listAll";&&&&&&&&} catch (Exception e) {&&&&&&&&&&&&e.printStackTrace();&&&&&&&&&&&&request.setAttribute("InfoMessage", "信息载入失败!具体异常信息:" + e.getMessage());&&&&&&&&&&&&return "result";&&&&&&&&}&&&&}&&&&&@SuppressWarnings("finally")&&&&@RequestMapping("del")&&&&public String del(String tid,HttpServletRequest request){&&&&&&&&try {&&&&&&&&&&&&&&&&&&&&&&&&String str = baseService.delete(tid);&&&&&&&&&&&&request.setAttribute("InfoMessage", str);&&&&&&&&} catch (Exception e) {&&&&&&&&&&&&e.printStackTrace();&&&&&&&&&&&&request.setAttribute("InfoMessage", "删除信息失败!具体异常信息:" + e.getMessage());&&&&&&&&} finally {&&&&&&&&&&&&&&&&&&&&&&&&return "result";&&&&&&&&}&&&&}&&&&@RequestMapping("modify")&&&&public String modify(String tid,HttpServletRequest request){&&&&&&&&try {&&&&&&&&&&&&&&&&&&&&&&&&Add add = baseService.findById(tid);&&&&&&&&&&&&request.setAttribute("add", add);&&&&&&&&&&&&return "modify";&&&&&&&&} catch (Exception e) {&&&&&&&&&&&&e.printStackTrace();&&&&&&&&&&&&request.setAttribute("InfoMessage", "信息载入失败!具体异常信息:" + e.getMessage());&&&&&&&&&&&&return "result";&&&&&&&&}&&&&}&&&&@SuppressWarnings("finally")&&&&@RequestMapping("update")&&&&public String update(Add add,HttpServletRequest request){&&&&&&&&try {&&&&&&&&&&&&&&&&&&&&&&&&String str = baseService.update(add);&&&&&&&&&&&&request.setAttribute("InfoMessage", str);&&&&&&&&} catch (Exception e) {&&&&&&&&&&&&e.printStackTrace();&&&&&&&&&&&&request.setAttribute("InfoMessage", "更新信息失败!具体异常信息:" + e.getMessage());&&&&&&&&} finally {&&&&&&&&&&&&&&&&&&&&&&&&return "result";&&&&&&&&}&&&&}&}
Service的实现
BaseServiceImpl.java
package com.bky.service.
import java.util.L
import java.util.UUID;
import org.springframework.beans.factory.annotation.A
import org.springframework.stereotype.S
import com.bky.dao.AddM
import com.bky.model.A
import com.bky.service.BaseS
@Service("baseService")
public class BaseServiceImpl implements BaseService {
private AddMapper addM
public AddMapper getAddMapper() {
return addM
@Autowired
public void setAddMapper(AddMapper addMapper) {
this.addMapper = addM
public String addInfo(Add addInfo) {
if (addMapper.insertSelective(addInfo) == 1) {
return "添加成功";
return "添加失败";
public List&Add& getAll() {
return addMapper.getAll();
public String delete(String id) {
if (addMapper.deleteByPrimaryKey(id) == 1) {
return "删除成功";
return "删除失败";
public Add findById(String id) {
return addMapper.selectByPrimaryKey(id);
public String update(Add addInfo) {
if (addMapper.updateByPrimaryKeySelective(addInfo) == 1) {
return "更新成功";
return "更新失败";
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
package com.bky.service.impl;&import java.util.List;import java.util.UUID;&import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service;&import com.bky.dao.AddMapper;import com.bky.model.Add;import com.bky.service.BaseService;&@Service("baseService")public class BaseServiceImpl implements BaseService {&&&&&private AddMapper addMapper;&&&&&public AddMapper getAddMapper() {&&&&&&&&return addMapper;&&&&}&&&&@Autowired&&&&public void setAddMapper(AddMapper addMapper) {&&&&&&&&this.addMapper = addMapper;&&&&}&&&&&@Override&&&&public String addInfo(Add addInfo) {&&&&&&&&if (addMapper.insertSelective(addInfo) == 1) {&&&&&&&&&&&&return "添加成功";&&&&&&&&}&&&&&&&&return "添加失败";&&&&}&&&&@Override&&&&public List&Add& getAll() {&&&&&&&&return addMapper.getAll();&&&&}&&&&@Override&&&&public String delete(String id) {&&&&&&&&if (addMapper.deleteByPrimaryKey(id) == 1) {&&&&&&&&&&&&return "删除成功";&&&&&&&&}&&&&&&&&return "删除失败";&&&&}&&&&@Override&&&&public Add findById(String id) {&&&&&&&&return addMapper.selectByPrimaryKey(id);&&&&}&&&&@Override&&&&public String update(Add addInfo) {&&&&&&&&if (addMapper.updateByPrimaryKeySelective(addInfo) == 1) {&&&&&&&&&&&&return "更新成功";&&&&&&&&}&&&&&&&&return "更新失败";&&&&}&}
AddMapper.xml
&?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.bky.dao.AddMapper" &
&resultMap id="BaseResultMap" type="com.bky.model.Add" &
&id column="id" property="id" jdbcType="VARCHAR" /&
&result column="tname" property="tname" jdbcType="VARCHAR" /&
&result column="tpwd" property="tpwd" jdbcType="VARCHAR" /&
&/resultMap&
&sql id="Base_Column_List" &
id, tname, tpwd
&select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" &
&include refid="Base_Column_List" /&
where id = #{id,jdbcType=VARCHAR}
&delete id="deleteByPrimaryKey" parameterType="java.lang.String" &
delete from tadd
where id = #{id,jdbcType=VARCHAR}
&insert id="insert" parameterType="com.bky.model.Add" &
insert into tadd (id, tname, tpwd
values (#{id,jdbcType=VARCHAR}, #{tname,jdbcType=VARCHAR}, #{tpwd,jdbcType=VARCHAR}
&insert id="insertSelective" parameterType="com.bky.model.Add" &
insert into tadd
&trim prefix="(" suffix=")" suffixOverrides="," &
&if test="id != null" &
&if test="tname != null" &
&if test="tpwd != null" &
&trim prefix="values (" suffix=")" suffixOverrides="," &
&if test="id != null" &
#{id,jdbcType=VARCHAR},
&if test="tname != null" &
#{tname,jdbcType=VARCHAR},
&if test="tpwd != null" &
#{tpwd,jdbcType=VARCHAR},
&update id="updateByPrimaryKeySelective" parameterType="com.bky.model.Add" &
update tadd
&if test="tname != null" &
tname = #{tname,jdbcType=VARCHAR},
&if test="tpwd != null" &
tpwd = #{tpwd,jdbcType=VARCHAR},
where id = #{id,jdbcType=VARCHAR}
&update id="updateByPrimaryKey" parameterType="com.bky.model.Add" &
update tadd
set tname = #{tname,jdbcType=VARCHAR},
tpwd = #{tpwd,jdbcType=VARCHAR}
where id = #{id,jdbcType=VARCHAR}
&select id="getAll" resultMap="BaseResultMap"&
SELECT * FROM tadd
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
&?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.bky.dao.AddMapper" &&&&resultMap id="BaseResultMap" type="com.bky.model.Add" &&&&&&id column="id" property="id" jdbcType="VARCHAR" /&&&&&&result column="tname" property="tname" jdbcType="VARCHAR" /&&&&&&result column="tpwd" property="tpwd" jdbcType="VARCHAR" /&&&&/resultMap&&&&sql id="Base_Column_List" &&&&&id, tname, tpwd&&&/sql&&&&select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" &&&&&select &&&&&include refid="Base_Column_List" /&&&&&from tadd&&&&where id = #{id,jdbcType=VARCHAR}&&&/select&&&&delete id="deleteByPrimaryKey" parameterType="java.lang.String" &&&&&delete from tadd&&&&where id = #{id,jdbcType=VARCHAR}&&&/delete&&&&insert id="insert" parameterType="com.bky.model.Add" &&&&&insert into tadd (id, tname, tpwd&&&&&&)&&&&values (#{id,jdbcType=VARCHAR}, #{tname,jdbcType=VARCHAR}, #{tpwd,jdbcType=VARCHAR}&&&&&&)&&&/insert&&&&insert id="insertSelective" parameterType="com.bky.model.Add" &&&&&insert into tadd&&&&&trim prefix="(" suffix=")" suffixOverrides="," &&&&&&&&if test="id != null" &&&&&&&&&id,&&&&&&&/if&&&&&&&&if test="tname != null" &&&&&&&&&tname,&&&&&&&/if&&&&&&&&if test="tpwd != null" &&&&&&&&&tpwd,&&&&&&&/if&&&&&&/trim&&&&&&trim prefix="values (" suffix=")" suffixOverrides="," &&&&&&&&if test="id != null" &&&&&&&&&#{id,jdbcType=VARCHAR},&&&&&&&/if&&&&&&&&if test="tname != null" &&&&&&&&&#{tname,jdbcType=VARCHAR},&&&&&&&/if&&&&&&&&if test="tpwd != null" &&&&&&&&&#{tpwd,jdbcType=VARCHAR},&&&&&&&/if&&&&&&/trim&&&&/insert&&&&update id="updateByPrimaryKeySelective" parameterType="com.bky.model.Add" &&&&&update tadd&&&&&set &&&&&&&&if test="tname != null" &&&&&&&&&tname = #{tname,jdbcType=VARCHAR},&&&&&&&/if&&&&&&&&if test="tpwd != null" &&&&&&&&&tpwd = #{tpwd,jdbcType=VARCHAR},&&&&&&&/if&&&&&&/set&&&&&where id = #{id,jdbcType=VARCHAR}&&&/update&&&&update id="updateByPrimaryKey" parameterType="com.bky.model.Add" &&&&&update tadd&&&&set tname = #{tname,jdbcType=VARCHAR},&&&&&&tpwd = #{tpwd,jdbcType=VARCHAR}&&&&where id = #{id,jdbcType=VARCHAR}&&&/update&&&&&select id="getAll" resultMap="BaseResultMap"&&&&&&&SELECT * FROM tadd&&&/select&&/mapper&
以上就是几个关键位置的代码,我全部贴出来了。至于配置文件什么的,由于时间原因没有贴出。如果大家要是感兴趣的话,可以下载我的这个演示项目包,里面的东西都齐全着,导入到MyEclipse上面直接部署到服务器上面就可以运行。数据库就是里面的那个.sql文件。建个库然后将数据导入就是。哦,对了。导完数据后,记得别忘了到config.properties里面去把数据库的连接信息换成你自己哦!
本次演示例子源码完整下载:(百度网盘)
假如百度云分享链接失效,请联系站长,我会补上的。
好了。到这里为止,关于 SSM框架整合的一个CRUD的完整Web例子到此就结束了。如果你在阅读代码的时候有什么疑惑或者不懂,欢迎和我探讨哦!
该日志由 BaiKeyang 于日发表在分类下
【上篇】【下篇】希望各位大神能帮我解决下面的java题目。分少 还望不要嫌弃。_百度知道
希望各位大神能帮我解决下面的java题目。分少 还望不要嫌弃。
jsp两个文件.jsp进行登录检验,假定SQLServer数据库的用户名为sa。(注,如果用户成功登录。要求,您已登录到系统”.htm,然后建立数据表users,显示“请输入正确的用户名与密码”,密码。否则,界面信息包括用户名。(2) 请写出创建数据表users的SQL命令,就提示“你好,表的数据结构如下,密码为sa,做一用户登录界面logon、在MS SQL Server数据库系统创建一个名为test的数据库.htm和logon、编写程序logon。2。(3) 请写出向数据表users插入用户名为Richard,密码为Richard的一条记录: 字段
nvarchar(20)
主键password
nvarchar(20)
非空(1) 请写出创建数据库test的SQL命令1:数据库名与,用jdbc对数据库进行连接。然后提交到logon
提问者采纳
Richard&#39.mdf&#39, -- 主数据文件的物理名称
size=5mb.create database test
-- 默认就属于primary文件组,[password])
('test_log&#39,
password nvarchar(20)
size=2test_data'.INSERT INTO users
([name]*--日志文件的具体描述:&#92,)go3,'test_users';
name='*--数据文件的具体描述--*&#47.use StuDBgo if exists(select * from sysobjects where name=&#39,
filename=&#39,
filegrowth=1mb )2;;D.ldf'
name=',各参数含义同上--*&#47,可省略 (
&#47, -- 主数据文件增长的最大值
filegrowth=15% --主数据文件的增长率 ) log on (
&#47, --主数据文件的初始大小
maxsize=100:\test_data,
-- 主数据文件的逻辑名称
filename=Ƈ)drop table userscreate table users(
name nvarchar(20)D;Richard&#39
提问者评价
谢谢你的耐心解答,好详细呀
其他类似问题
为您推荐:
其他2条回答
朋友,刚学吧,自己做,不难,不然怎么能成长,别人做始终的别人的,代码不敲光看可没用,我给你个思路,
create database test 之前先判断是不是有这个库,有就删掉,
create table users 可以使用mysql建,不过建议手动,
insert into users values('Richard','Richard') 数据插完了,
jdbc 的话,肯定是没有框架,那个代码很长,但是不难,
给四个常量,放用户名,密码,驱动,地址,这四个项放在一个数据库连接类里,
这个类包含开关库,增删改查方法,
页面调用时,应该是使用了servlet或者action具体哪一个看你们现在学到什么阶段
最后就是很简单的一个页面,一个form两个输入框一个按钮,表单下加个层,用于显示错误信息,或者用struts标签也行
剩下的没什么好说了,jdbc很久不用了,不足之处多...
这个只有自己做才会有提高的。
您可能关注的推广回答者:
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁

我要回帖

更多关于 据说只有大神才能看懂 的文章

 

随机推荐