第一步:使用yum list mysql*
第二步:使用命令安装yum install mysql*
在左边空白处右键--新建数据库---设置编码集和数据库名
在建好的数据库上右键----运行sql文件---找到已经准备好的sql文件,执行即可
这样就得到了一个数据库
File--inport--
根据自己的实际情况修改连接数据库的配置文件
执行该文件即可
Dao层:
Mybatis的配置文件:SqlMapConfig.xml
不需要配置任何内容,需要有文件头。文件必须存在。
applicationContext-dao.xml:
mybatis整合spring,通过由spring创建数据库连接池,spring管理SqlSessionFactory、mapper代理对象。需要mybatis和spring的整合包。
Service层:
applicationContext-service.xml:
所有的service实现类都放到spring容器中管理。并由spring管理事务。
表现层:
Springmvc框架,由springmvc管理controller。
Springmvc的三大组件。
在e3-manager\e3-manager-web\src\main\resources目录下创建三个文件夹conf mybatis spring
e3-manager\e3-manager-web\src\main\resources\mybatis:SqlMapConfig.xml
不需要配置任何内容,需要有文件头。文件必须存在。
e3-manager\e3-manager-web\src\main\resources\applicationContext-dao.xml:
mybatis整合spring,通过由spring创建数据库连接池,spring管理SqlSessionFactory、mapper代理对象。需要mybatis和spring的整合包。
Service层:
e3-manager\e3-manager-web\src\main\resources\applicationContext-service.xml:
所有的service实现类都放到spring容器中管理。并由spring管理事务。
e3-manager\e3-manager-web\src\main\resources\applicationContext-trans.xml
表现层:
Springmvc框架,由springmvc管理controller。
Springmvc的三大组件。
e3-manager\e3-manager-web\src\main\resources\springmvc.xml
web.xml
e3-manager-web
index.html
index.htm
index.jsp
default.html
default.htm
default.jsp
contextConfigLocation
classpath:spring/applicationContext-*.xml
org.springframework.web.context.ContextLoaderListener
CharacterEncodingFilter
org.springframework.web.filter.CharacterEncodingFilter
encoding
utf-8
CharacterEncodingFilter
/*
e3-manager
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:spring/springmvc.xml
1
e3-manager
/
需求
根据商品id查询商品信息,返回json数据。(ItemService)
由于是单表查询可以使用逆向工程生成的代码
参数:商品id
返回值:TbItem
业务逻辑:根据商品id查询商品信息。
编写interface接口
package cn.e3mall.service;
import cn.e3mall.pojo.TbItem;
public interface ItemService {
/**
* 根据id查询商品
* @param id
* @return
*/
public TbItem getItemById(long id);
}
编写实现类
package cn.e3mall.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.e3mall.mapper.TbItemMapper;
import cn.e3mall.pojo.TbItem;
@Service
public class ItemServiceImpl implements ItemService {
@Autowired
private TbItemMapper itemMapper;
@Override
public TbItem getItemById(long id) {
TbItem item = itemMapper.selectByPrimaryKey(id);
return item;
}
}
package cn.e3mall.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.e3mall.pojo.TbItem;
import cn.e3mall.service.ItemService;
@Controller
public class ItemController {
@Autowired
private ItemService itemService;
@RequestMapping("item/{itemId}")
@ResponseBody
private TbItem getItemById(@PathVariable Long itemId){
TbItem item = itemService.getItemById(itemId);
return item;
}
}