SpringMVC综合使用手机管理系统Controller层开发
1. beans.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:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.2.xsd">
<context:property-placeholder location="classpath:conf/jdbc.properties" />
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${con.driverClassName}"></property>
<property name="url" value="${con.url}"></property>
<property name="username" value="${con.username}"></property>
<property name="password" value="${con.password}"></property>
<property name="maxActive" value="${con.maxActive}"></property>
<property name="initialSize" value="${con.initialSize}"></property>
<property name="maxIdle" value="${con.maxIdle}"></property>
<property name="minIdle" value="${con.minIdle}"></property>
</bean>
<!-- mybatis文件配置,扫描所有mapper文件 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"
p:dataSource-ref="dataSource" p:configLocation="classpath:conf/mybatis-config.xml"
p:mapperLocations="classpath:mapper/*.xml" /><!-- configLocation为mybatis属性
mapperLocations为所有mapper -->
<!-- spring与mybatis整合配置,扫描所有dao -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"
p:basePackage="com.green.phonemanage.dao" p:sqlSessionFactoryBeanName="sqlSessionFactory" />
<!-- 对数据源进行事务管理 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
p:dataSource-ref="dataSource" />
<tx:annotation-driven transaction-manager="transactionManager" />
<context:annotation-config />
<!-- 设置不过滤内容,比如:css,jquery,img 等资源文件 -->
<mvc:default-servlet-handler/>
<bean class="com.green.phonemanage.service.impl.ClientServiceImpl"
id="clientService"></bean>
<bean class="com.green.phonemanage.service.impl.PhoneServiceImpl"
id="phoneService"></bean>
<bean class="com.green.phonemanage.service.impl.UserServiceImpl"
id="userService"></bean>
<context:component-scan base-package="com.green.phonemanage.controller"></context:component-scan>
<mvc:annotation-driven></mvc:annotation-driven>
<!-- Freemarker配置 -->
<bean id="freemarkerConfig"
class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
<property name="templateLoaderPath" value="/WEB-INF/fl/" />
<property name="freemarkerSettings">
<props>
<prop key="template_update_delay"></prop>
<prop key="default_encoding">UTF-</prop>
<prop key="number_format">.##########</prop>
<prop key="datetime_format">yyyy-MM-dd HH:mm:ss</prop>
<prop key="classic_compatible">true</prop>
<prop key="template_exception_handler">ignore</prop>
</props>
</property>
</bean>
<!--视图解释器 -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
<property name="suffix">
<value>.html</value>
</property>
<property name="contentType" value="text/html;charset=UTF-8"></property>
<property name="requestContextAttribute" value="base"></property>
</bean>
<!-- 通过注解对数据处理的适配 -->
<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<bean
class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>application/json;charset=UTF-</value>
<value>text/plain;charset=UTF-</value>
</list>
</property>
</bean>
<bean
class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" />
</list>
</property>
</bean>
2. LoginController
package com.green.phonemanage.controller;
import java.util.ArrayList;
import java.util.List;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import com.green.phonemanage.model.MenuItem;
@Controller
public class LoginController {
@RequestMapping(value="/web/toIndex",method=RequestMethod.GET)
public ModelAndView loginToIndex(String loginName,int role,int userId){
ModelAndView andView=new ModelAndView("index");
andView.addObject("loginName",loginName);
andView.addObject("role", role);
andView.addObject("userId", userId);
return andView;
} }
3. UserController
package com.green.phonemanage.controller;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.green.phonemanage.dao.UserDao;
import com.green.phonemanage.model.Msg;
import com.green.phonemanage.model.SearchForm;
import com.green.phonemanage.model.User;
import com.green.phonemanage.model.UserMsg;
import com.green.phonemanage.service.IUserService;
@RestController
public class UserController {
@Autowired
private IUserService userService;
public void setUserService(IUserService userService) {
this.userService = userService;
}
@Autowired
private UserDao userDao;
public void setUserDao(UserDao userDao) {
this.userDao = userDao;
}
/*
* �û���¼
*
* @param:��¼��
*
* @param:����
*
* @param:��ɫ��1.�ͻ���2������Ա
*
* @return:��¼��Ϣ
*/
@RequestMapping(value = "/user/login", method = RequestMethod.POST)
public UserMsg login(@RequestParam String loginName, @RequestParam String passwd,
@RequestParam int role) {
User user = new User();
user.setLoginName(loginName);
user.setPasswd(passwd);
user.setRole(role);
return userService.login(user);
}
/*
* �û�ע��
*
* @param:�û���Ϣ
*
* @return:�û�ע����Ϣ
*/
@RequestMapping(value = "user/register", method = RequestMethod.POST,produces="application/json",consumes="application/json")
public UserMsg register(@RequestBody User user) {
user.setStatus(1);
return userService.register(user);
}
/*
* 查询登录名是否存在
*
* @param:登录名
*
* @return:状态
*/
@RequestMapping(value = "user/ne", method = RequestMethod.GET)
public UserMsg nameExist(@RequestParam("loginName") String loginName) {
UserMsg um = new UserMsg();
um.setMsg("登录名不存在");
um.setStatus(1);
Integer id = userDao.findByLoginName(loginName);
if (id != null) {
um.setStatus(0);
um.setMsg("登录名已经存在");
}
return um;
}
/*
* ͨ��id��ȡ�û���Ϣ
*
* @param:�û�id
*
* @return:�û���Ϣ
*/
@RequestMapping(value = "user/find", method = RequestMethod.GET)
public User findUser(@RequestParam("id") int id) {
return userDao.findById(id);
}
/*
* �û���Ϣ��ҳ��ѯ
*
* @param:��ҳ��Ϣ
*
* @return:�û���Ϣ�б�
*/
@RequestMapping(value = "user/finds", method = RequestMethod.POST)
public Map<String, Object> finds(SearchForm searchForm) {
searchForm.setPageIndex(searchForm.getPageIndex() * searchForm.getPageSize());
List<User> users = userDao.finds(searchForm);
Map<String, Object> datas = new HashMap<String, Object>();
datas.put("data", users);
datas.put("total", userDao.totals()==null?0:userDao.totals());
return datas;
}
/*
* ɾ��ָ�����û�
*
* @param:�û�id
*
* @return:��Ϣ
*/
@RequestMapping(value = "user/rm", method = RequestMethod.GET)
public Msg remove(@RequestParam("id") int id) {
Msg rmMsg = new Msg();
rmMsg.setId(id);
rmMsg.setMsg("ɾ���ɹ�");
rmMsg.setState(1);
try {
userDao.rmove(id);
} catch (Exception e) {
rmMsg.setState(0);
rmMsg.setMsg("ɾ��ʧ��");
}
return rmMsg;
}
/*
* ���û���Ϣ
*
* @param:�û�id
*
* @return:�û�״̬
*/
@RequestMapping(value = "user/update", method = RequestMethod.POST)
public Msg update(User user) {
Msg rmMsg = new Msg();
rmMsg.setId(user.getId());
rmMsg.setMsg("�ijɹ�");
rmMsg.setState(1);
try {
userDao.update(user);
} catch (Exception e) {
rmMsg.setState(0);
rmMsg.setMsg("��ʧ��");
}
return rmMsg;
}
/*
* �û�����
*
* @param:�û�id
*
* @return:���ز���״̬
*/
@RequestMapping(value = "user/freeze", method = RequestMethod.GET)
public Msg freeze(@RequestParam("id") int id) {
Msg msg = new Msg();
msg.setId(id);
msg.setState(1);
msg.setMsg("成功");
try {
userDao.freeze(id);
} catch (Exception e) {
msg.setState(0);
msg.setMsg("失败");
}
return msg;
}
/*
* �û��ⶳ
*
* @param:�û�id
*
* @return:���ز���״̬
*/
@RequestMapping(value = "user/unfreeze", method = RequestMethod.GET)
public Msg unfreeze(@RequestParam("id") int id) {
Msg msg = new Msg();
msg.setId(id);
msg.setState(1);
msg.setMsg("成功");
try {
userDao.unfreeze(id);
} catch (Exception e) {
msg.setState(0);
msg.setMsg("失败");
}
return msg;
}
}
4. ClientController
package com.green.phonemanage.controller;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonAnyFormatVisitor;
import com.fasterxml.jackson.databind.util.JSONPObject;
import com.green.phonemanage.dao.CellPhoneDao;
import com.green.phonemanage.dao.ClientDao;
import com.green.phonemanage.model.Client;
import com.green.phonemanage.model.Msg;
import com.green.phonemanage.model.SearchForm;
import com.green.phonemanage.service.IClientService;
;
@RestController
public class ClientController {
private Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private IClientService clientService;
public void setClientService(IClientService clientService) {
this.clientService = clientService;
}
@Autowired
private CellPhoneDao cellPhoneDao;
public void setCellPhoneDao(CellPhoneDao cellPhoneDao) {
this.cellPhoneDao = cellPhoneDao;
}
@Autowired
private ClientDao clientDao;
public void setClientDao(ClientDao clientDao) {
this.clientDao = clientDao;
}
@RequestMapping(value = "/tst", method = RequestMethod.GET)
public void tst(@RequestParam("id") int id) {
System.out.println("This is a test.");
}
/*
* 通鏌ユ壘瀹㈡埛
*
* @param:瀹㈡埛id
*
* @return:瀹㈡埛淇℃伅
*/
@RequestMapping(value = "/client/find", method = RequestMethod.GET, produces = "application/json", consumes = "application/json")
public Client findUser(@RequestParam("id") int id) {
return clientDao.findById(id);
}
/*
* 鍒嗛〉鑾峰彇瀹㈡埛淇℃伅
*
* @param:鍒嗛〉淇℃伅
*
* @return:鍒嗛〉鎵�鏈夊鎴蜂俊鎭�
*/
@RequestMapping(value = "client/finds", method = RequestMethod.POST)
public Map<String, Object> finds(SearchForm searchForm) {
searchForm.setPageIndex(searchForm.getPageIndex()
* searchForm.getPageSize());
List<Client> r = clientDao.finds(searchForm);
Map<String, Object> datas = new HashMap<String, Object>();
datas.put("data", r);
datas.put("total", clientDao.totals()==null?0:clientDao.totals());
return datas;
}
/*
* 绉婚櫎瀹㈡埛
*
* @param:瀹㈡埛id
*
* @return:鐘舵��
*/
@RequestMapping(value = "client/rm", method = RequestMethod.GET)
public Msg remove(@RequestParam("id") int id) {
Msg rmMsg = new Msg();
rmMsg.setId(id);
rmMsg.setMsg("刪除成功");
rmMsg.setState(1);
try {
Integer phoneId=null;
phoneId=cellPhoneDao.findByClient(id);
if(null==phoneId){
clientDao.rmove(id);
}else{
rmMsg.setState(0);
rmMsg.setMsg("手机被使用的用户,无法删除。");
}
} catch (Exception e) {
rmMsg.setState(0);
rmMsg.setMsg("手机被使用的用户,无法删除。");
}
return rmMsg;
}
/*
* 淇敼瀹㈡埛淇℃伅
*
* @param:瀹㈡埛淇℃伅
*
* @return:鐘舵�佔刺�
*
* @RequestMapping(value = "client/update", method = RequestMethod.POST)
* public Msg update(@ModelAttribute("client") Client client) {
*
* Msg rmMsg = new Msg(); rmMsg.setId(client.getId());
* rmMsg.setMsg("绉婚櫎鎴愬姛"); rmMsg.setState(1); try {
* clientDao.update(client); } catch (Exception e) { rmMsg.setState(0);
* rmMsg.setMsg("绉婚櫎澶辫触"); } return rmMsg; }
*/
/*
* 娣诲姞瀹㈡埛淇℃伅
*
* @param:瀹㈡埛淇℃伅
*
* @return:鐘舵�佔刺�
*/
@RequestMapping(value = "client/add", method = RequestMethod.POST, produces = "application/json", consumes = "application/json")
public Msg add(@RequestBody Client client) {
logger.debug(client.toString());
Msg rmMsg = new Msg();
rmMsg.setId(client.getId());
rmMsg.setMsg("修改成功");
rmMsg.setState(1);
try {
clientService.add(client);
} catch (Exception e) {
rmMsg.setState(0);
rmMsg.setMsg("客戶已經存在");
}
return rmMsg;
}
}
5. CellPhoneController
package com.green.phonemanage.controller;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.green.phonemanage.dao.CellPhoneDao;
import com.green.phonemanage.model.CellPhone;
import com.green.phonemanage.model.Msg;
import com.green.phonemanage.model.SearchForm;
import com.green.phonemanage.service.IPhoneService;
@RestController
public class CellPhoneController {
@Autowired
private IPhoneService phoneService;
public void setPhoneService(IPhoneService phoneService) {
this.phoneService = phoneService;
}
@Autowired
private CellPhoneDao cellPhoneDao;
public void setCellPhoneDao(CellPhoneDao cellPhoneDao) {
this.cellPhoneDao = cellPhoneDao;
}
/*
* ͨ查找手机
*
* @param:手机id
*
* @return:手机信息
*/
@RequestMapping(value = "cellphone/find", method = RequestMethod.GET)
public CellPhone findUser(@RequestParam("id") int id) {
return cellPhoneDao.findById(id);
}
/*
* 分页获取手机信息
*
* @param:分页信息
*
* @return:分页所有手机信息
*/
@RequestMapping(value = "cellphone/finds", method = RequestMethod.POST)
public Map<String, Object> finds(SearchForm searchForm) {
searchForm.setPageIndex(searchForm.getPageIndex() * searchForm.getPageSize());
List<CellPhone>r= cellPhoneDao.finds(searchForm);
Map<String, Object> datas = new HashMap<String, Object>();
datas.put("data", r);
datas.put("total", cellPhoneDao.totals()==null?0:cellPhoneDao.totals());
return datas;
}
/*
* 移除手机
*
* @param:手机id
*
* @return:状态
*/
@RequestMapping(value = "cellphone/rm", method = RequestMethod.GET)
public Msg remove(@RequestParam("id") int id) {
Msg rmMsg = new Msg();
rmMsg.setId(id);
rmMsg.setMsg("删除成功");
rmMsg.setState(1);
try {
cellPhoneDao.rmove(id);
} catch (Exception e) {
rmMsg.setState(0);
rmMsg.setMsg("删除失败");
}
return rmMsg;
}
/*
* 修改手機信息
*
* @param:手機信息
*
* @return:状态״̬
*/
@RequestMapping(value = "cellphone/update", method = RequestMethod.POST,consumes="application/json")
public Msg update(@RequestBody CellPhone cellphone) {
Msg rmMsg = new Msg();
rmMsg.setId(cellphone.getId());
rmMsg.setMsg("移除成功");
rmMsg.setState(1);
try {
phoneService.add(cellphone);
} catch (Exception e) {
rmMsg.setState(0);
rmMsg.setMsg("移除失败");
}
return rmMsg;
}
/*
* 添加手机信息
*
* @param:手机信息
*
* @return:状态״̬
*/
@RequestMapping(value = "cellphone/add", method = RequestMethod.POST,consumes="application/json")
public Msg add(@RequestBody CellPhone cellphone) {
cellphone.setStatus(1);
Msg rmMsg = new Msg();
rmMsg.setId(cellphone.getId());
rmMsg.setMsg("添加成功");
rmMsg.setState(1);
try {
phoneService.add(cellphone);
} catch (Exception e) {
rmMsg.setState(0);
rmMsg.setMsg("添加失败");
}
return rmMsg;
}
}
6. MenuController
package com.green.phonemanage.controller;
import java.util.ArrayList;
import java.util.List;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.green.phonemanage.model.MenuItem;
@RestController
public class MenuController {
@RequestMapping(value = "/menu", method = RequestMethod.GET,produces="application/json")
public List<MenuItem> menu(int role){
List<MenuItem>items=new ArrayList<MenuItem>();
if(role==1){
MenuItem itemTop=new MenuItem();
itemTop.setId("top");
itemTop.setIconCls("icon-add");
itemTop.setText("系统管理");
items.add(itemTop);
MenuItem itemPhone=new MenuItem();
itemPhone.setId("phone");
itemPhone.setText("手机管理");
itemPhone.setIconCls("Phone");
itemPhone.setUid("top");
itemPhone.setIconPosition("top");
itemPhone.setUrl("web/cellphone/index");
items.add(itemPhone);
MenuItem itemClient=new MenuItem();
itemClient.setId("client");
itemClient.setText("客户管理");
itemClient.setIconCls("Client");
itemClient.setUid("top");
itemClient.setIconPosition("top");
itemClient.setUrl("web/client/index");
items.add(itemClient);
MenuItem itemUser=new MenuItem();
itemUser.setId("user");
itemUser.setText("用户设置");
itemUser.setUid("top");
itemUser.setIconPosition("top");
itemUser.setIconCls("User");
itemUser.setUrl("web/user/edit");
items.add(itemUser);
}
if(role==2){
MenuItem itemTop=new MenuItem();
itemTop.setId("top");
itemTop.setIconCls("icon-add");
itemTop.setText("系统管理");
items.add(itemTop);
MenuItem itemPhone=new MenuItem();
itemPhone.setId("phone");
itemPhone.setText("手机管理");
itemPhone.setIconCls("Phone");
itemPhone.setUid("top");
itemPhone.setIconPosition("top");
itemPhone.setUrl("web/cellphone/index");
items.add(itemPhone);
MenuItem itemClient=new MenuItem();
itemClient.setId("client");
itemClient.setText("客户管理");
itemClient.setIconCls("Client");
itemClient.setUid("top");
itemClient.setIconPosition("top");
itemClient.setUrl("web/client/index");
items.add(itemClient);
MenuItem itemUser=new MenuItem();
itemUser.setId("user");
itemUser.setText("用户管理");
itemUser.setUid("top");
itemUser.setIconPosition("top");
itemUser.setIconCls("User");
itemUser.setUrl("web/user/index");
items.add(itemUser);
MenuItem itemPwd=new MenuItem();
itemPwd.setId("pwd");
itemPwd.setText("修改密码");
itemPwd.setUid("top");
itemPwd.setIconPosition("top");
itemPwd.setIconCls("Pwd");
itemPwd.setUrl("web/user/edit/pwd");
items.add(itemPwd);
}
MenuItem itemTop2=new MenuItem();
itemTop2.setId("top2");
itemTop2.setIconCls("icon-add");
itemTop2.setText("分析");
items.add(itemTop2);
MenuItem itemStatus=new MenuItem();
itemStatus.setId("status");
itemStatus.setText("状态");
itemStatus.setUid("top2");
itemStatus.setIconPosition("left");
itemStatus.setIconCls("status");
itemStatus.setUrl("web/bar/status");
items.add(itemStatus);
MenuItem itemBrand=new MenuItem();
itemBrand.setId("brand");
itemBrand.setText("品牌");
itemBrand.setUid("top2");
itemBrand.setIconPosition("left");
itemBrand.setIconCls("brand");
itemBrand.setUrl("web/bar/brand");
items.add(itemBrand);
MenuItem itemCity=new MenuItem();
itemCity.setId("city");
itemCity.setText("地址");
itemCity.setUid("top2");
itemCity.setIconPosition("left");
itemCity.setIconCls("city");
itemCity.setUrl("web/bar/address");
items.add(itemCity);
return items;
}
7. BarViewController
package com.green.phonemanage.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
@Controller
@RequestMapping("/web/bar/")
public class BarViewController {
@RequestMapping(value = "status", method = RequestMethod.GET)
public ModelAndView toStatus() {
ModelAndView andView = new ModelAndView("/bar/status"); return andView;
}
@RequestMapping(value = "address", method = RequestMethod.GET)
public ModelAndView toAddress() {
ModelAndView andView = new ModelAndView("/bar/address"); return andView;
}
@RequestMapping(value = "brand", method = RequestMethod.GET)
public ModelAndView toBrand() {
ModelAndView andView = new ModelAndView("/bar/brand"); return andView;
}
}
8. CellPhoneViewController
package com.green.phonemanage.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
@RequestMapping("/web/cellphone/")
@Controller
public class CellPhoneViewController {
@RequestMapping(value = "index", method = RequestMethod.GET)
public ModelAndView index() {
ModelAndView andView = new ModelAndView("cellphone/index");
return andView;
}
@RequestMapping(value = "edit", method = RequestMethod.GET)
public ModelAndView edit() {
ModelAndView andView = new ModelAndView("cellphone/edit");
return andView;
}
@RequestMapping(value = "aedit", method = RequestMethod.GET)
public ModelAndView aedit() {
ModelAndView andView = new ModelAndView("cellphone/aedit");
return andView;
}
}
9. ClientViewController
package com.green.phonemanage.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
@Controller
@RequestMapping("/web/client")
public class ClientViewController {
@RequestMapping(value = "index", method = RequestMethod.GET)
public ModelAndView index() {
ModelAndView andView = new ModelAndView("client/index");
return andView;
}
@RequestMapping(value = "edit", method = RequestMethod.GET)
public ModelAndView edit() {
ModelAndView andView = new ModelAndView("client/edit");
return andView;
}
@RequestMapping(value = "eindex", method = RequestMethod.GET)
public ModelAndView aedit() {
ModelAndView andView = new ModelAndView("client/eindex");
return andView;
}
}
10. TotalController
package com.green.phonemanage.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.green.phonemanage.model.SearchTotal;
import com.green.phonemanage.service.IPhoneService;
@RestController
public class TotalController {
@Autowired
private IPhoneService phoneService;
public void setPhoneService(IPhoneService phoneService) {
this.phoneService = phoneService;
}
@RequestMapping(value = "/total/data", method = RequestMethod.GET)
public List<SearchTotal> datas(int type) {
return phoneService.findTotal(type);
}
}
11. UserViewController
package com.green.phonemanage.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
@Controller
@RequestMapping("/web/user/")
public class UserViewController {
@RequestMapping(value = "index", method = RequestMethod.GET)
public ModelAndView index() {
ModelAndView andView = new ModelAndView("/user/index"); return andView;
}
@RequestMapping(value = "edit", method = RequestMethod.GET)
public ModelAndView edit() {
ModelAndView andView = new ModelAndView("/user/edit");
return andView;
}
@RequestMapping(value = "edit/pwd", method = RequestMethod.GET)
public ModelAndView editPwd() {
ModelAndView andView = new ModelAndView("/user/pwdedit");
return andView;
}
}
以上是近期一个简单管理系统SpringMVC用法,其中前端用的是miniui框架。
SpringMVC综合使用手机管理系统Controller层开发的更多相关文章
- ssh_maven之controller层开发
我们已经完成了前两层的开发,现在 只剩下我们的controller层了,对于这一层,我们需要创建一个动作类CustomerAction,另外就是我们的strutss.xml以及我们的applicati ...
- PowerMock+SpringMVC整合并测试Controller层方法
PowerMock扩展自Mockito,实现了Mockito不支持的模拟形式的单元测试.PowerMock实现了对静态方法.构造函数.私有方法以及final方法的模拟支持,对静态初始化过程的移除等强大 ...
- Springmvc入门基础(五) ---controller层注解及返回类型解说
0.@Controller注解 作用:通过@Controller注解,注明该类为controller类,即控制器类,需要被spring扫描,然后注入到IOC容器中,作为Spring的Bean来管理,这 ...
- SpringMVC在Controller层中注入request的坑
记一次为了节省代码没有在方法体中声明HttpServletRequest,而用autowire直接注入所钻的坑 结论 给心急的人. 直接在Controller的成员变量上使用@Autowire声明Ht ...
- SpringMVC的controller层接收来自jsp页面通过<a href="/user/userUpdateInfo/>的中文乱码问题
这种情况是,jsp页面的中文正常显示,数据的中文也是正常显示,但是在Controller层接收到的中文是乱码,如下图所示: 解决方法:在Controller层对前台传递的中文乱码进行处理,将它转换成u ...
- springmvc controller层接收List类型的参数
Spring MVC在接收集合请求参数时,需要在Controller方法的集合参数里前添加@RequestBody,而@RequestBody默认接收的enctype (MIME编码)是applica ...
- springMVC中controller层方法中使用private和public问题
楼主一直习惯使用public,偶尔手误也可能使用private,但是发觉也没啥区别,都能调用service层,注入bean. 后来做一个新项目时,发觉自己以前的写的部分功能报错,当时有点懵逼,,找了半 ...
- Winform开发框架之客户关系管理系统(CRM)的开发总结系列2-基于框架的开发过程
在上篇随笔<Winform开发框架之客户关系管理系统(CRM)的开发总结系列1-界面功能展示>中介绍了我的整个CRM系统的概貌,本篇继续本系列的文章,介绍如何基于我的<winform ...
- SSH综合练习-仓库管理系统-第二天
SSH综合练习-仓库管理系统-第二天 今天的主要内容: 货物入库 页面信息自动补全回显功能:(学习目标:练习Ajax交互) 根据货物简记码来自动查询回显已有货物(Ajax回显) 根据货物名来自动查询补 ...
随机推荐
- HTML5自定义属性对象dataset
前面转载的"图片懒加载",因为基础不好,里面判断dataset的语句看不懂,经别人推荐找到一篇专门讲解dataset的文章,我心甚悦^ http://www.zhangxinxu. ...
- Firefox下载文件时中文名乱码问题
为了形象化,先看几张不同浏览器下下载文件时的效果图: 1:Firefox 36.0.1 2:IE8 3:Chrome 40.0.2214.93 m 4:360 7.1.1.322 很明显在Firefo ...
- 学习总结 JAVA环境配置 及其相应的步骤
相应的操作步骤 第一步: 右键我的电脑→属性→高级系统设置→环境变量→打开环境变量 第二步:在系统变量中添加JAVA_HOME ,并引用到相对应的地址. 第三步:在系统变量 path 中最前端(按ho ...
- C# 特性Attributes 和反射
一,Attributes 类新建一个子类,DetailAttributes 二, 在类的属性声明上面加Attributes public class testAttributes { [Detail( ...
- 做好SEO需要掌握的20个基础知识
作为一个网站优化者,有一些基础seo知识点是大家必须要掌握的,网站排名的好快,和这些基础的SEO优化知识有没做好,有没做到位,有着直接的关系!今天,伟伟SEO就把我前面讲的SEO优化基础知识做个总结, ...
- 【Framework】HTTP运行期与页面执行模型
HTTP运行期 HTTP运行期处理客户端应用程序(例如Web浏览器)进入的一个Web请求,通过处理它的应用程序的适当组件路由请求,然后产生响应并发回提出请求的客户端应用程序. 进入的HTTP Web请 ...
- Oracle笔记 十四、查询XML操作、操作系统文件
--1.随机数 select dbms_random.value from dual; select mod(dbms_random.random, 10) from dual; --0-9随机数 s ...
- boost:thread使用实例
/************************************************************************/ /*功能描述: boost thread使用实例 ...
- 电脑U盘启动总结
1:联想G410(笔记本) FN+F2:进入BIOS,FN+F12,快速启动选择. boot mode—>Legacy support,boot priority—>Legacy firs ...
- use python get information from one page
#!/usr/bin/python read = file('thread-1554-1-1.html','r') wr = file('list','w') while 1: line=read.r ...