Skip to content

Commit

Permalink
新增2个表和对应的实体、Mapper
Browse files Browse the repository at this point in the history
  • Loading branch information
abel533 committed Jan 31, 2016
1 parent 0fdc295 commit 8803706
Show file tree
Hide file tree
Showing 14 changed files with 693 additions and 52 deletions.
17 changes: 17 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,23 @@
<artifactId>mysql-connector-java</artifactId>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-parameter-names</artifactId>
</dependency>

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/tk/mybatis/springboot/conf/WebMvcConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,17 @@

package tk.mybatis.springboot.conf;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfig;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
import org.springframework.web.servlet.view.freemarker.FreeMarkerView;
import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;
import org.springframework.web.servlet.view.json.MappingJackson2JsonView;

/**
* @author liuzh_3nofxnp
Expand All @@ -40,4 +48,16 @@ public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
}

// @Override
// public void configureViewResolvers(ViewResolverRegistry registry) {
// registry.enableContentNegotiation(new MappingJackson2JsonView());
// registry.freeMarker().cache(false);
// }
//
// @Bean
// public FreeMarkerConfigurer freeMarkerConfigurer() {
// FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
// configurer.setTemplateLoaderPath("/WEB-INF/");
// return configurer;
// }
}
85 changes: 85 additions & 0 deletions src/main/java/tk/mybatis/springboot/controller/CityController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2014-2016 [email protected]
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package tk.mybatis.springboot.controller;

import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import tk.mybatis.springboot.model.City;
import tk.mybatis.springboot.service.CityService;

import java.util.List;

/**
* @author liuzh
* @since 2015-12-19 11:10
*/
@RestController
@RequestMapping("/cities")
public class CityController {

@Autowired
private CityService cityService;

@RequestMapping
public PageInfo<City> getAll(City city) {
List<City> countryList = cityService.getAll(city);
return new PageInfo<City>(countryList);
}

@RequestMapping(value = "/add")
public City add() {
return new City();
}

@RequestMapping(value = "/view/{id}")
public City view(@PathVariable Integer id) {
ModelAndView result = new ModelAndView();
City city = cityService.getById(id);
return city;
}

@RequestMapping(value = "/delete/{id}")
public ModelMap delete(@PathVariable Integer id) {
ModelMap result = new ModelMap();
cityService.deleteById(id);
result.put("msg", "删除成功!");
return result;
}

@RequestMapping(value = "/save", method = RequestMethod.POST)
public ModelMap save(City city) {
ModelMap result = new ModelMap();
String msg = city.getId() == null ? "新增成功!" : "更新成功!";
cityService.save(city);
result.put("city", city);
result.put("msg", msg);
return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2014-2016 [email protected]
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package tk.mybatis.springboot.controller;

import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import tk.mybatis.springboot.model.UserInfo;
import tk.mybatis.springboot.service.UserInfoService;

import java.util.List;

/**
* @author liuzh
* @since 2015-12-19 11:10
*/
@RestController
@RequestMapping("/users")
public class UserInfoController {

@Autowired
private UserInfoService userInfoService;

@RequestMapping
public PageInfo<UserInfo> getAll(UserInfo userInfo) {
List<UserInfo> userInfoList = userInfoService.getAll(userInfo);
return new PageInfo<UserInfo>(userInfoList);
}

@RequestMapping(value = "/add")
public UserInfo add() {
return new UserInfo();
}

@RequestMapping(value = "/view/{id}")
public UserInfo view(@PathVariable Integer id) {
ModelAndView result = new ModelAndView();
UserInfo userInfo = userInfoService.getById(id);
return userInfo;
}

@RequestMapping(value = "/delete/{id}")
public ModelMap delete(@PathVariable Integer id) {
ModelMap result = new ModelMap();
userInfoService.deleteById(id);
result.put("msg", "删除成功!");
return result;
}

@RequestMapping(value = "/save", method = RequestMethod.POST)
public ModelMap save(UserInfo userInfo) {
ModelMap result = new ModelMap();
String msg = userInfo.getId() == null ? "新增成功!" : "更新成功!";
userInfoService.save(userInfo);
result.put("userInfo", userInfo);
result.put("msg", msg);
return result;
}
}
35 changes: 35 additions & 0 deletions src/main/java/tk/mybatis/springboot/mapper/CityMapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2014-2016 [email protected]
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package tk.mybatis.springboot.mapper;

import tk.mybatis.springboot.model.City;
import tk.mybatis.springboot.util.MyMapper;

/**
* @author liuzh_3nofxnp
* @since 2016-01-22 22:17
*/
public interface CityMapper extends MyMapper<City> {
}
35 changes: 35 additions & 0 deletions src/main/java/tk/mybatis/springboot/mapper/UserInfoMapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2014-2016 [email protected]
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package tk.mybatis.springboot.mapper;

import tk.mybatis.springboot.model.UserInfo;
import tk.mybatis.springboot.util.MyMapper;

/**
* @author liuzh_3nofxnp
* @since 2016-01-22 22:17
*/
public interface UserInfoMapper extends MyMapper<UserInfo> {
}
70 changes: 70 additions & 0 deletions src/main/java/tk/mybatis/springboot/model/BaseEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2014-2016 [email protected]
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package tk.mybatis.springboot.model;

import javax.persistence.*;

/**
* 基础信息
*
* @author liuzh
* @since 2016-01-31 21:42
*/
public class BaseEntity {
@Id
@Column(name = "Id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;

@Transient
private Integer page = 1;

@Transient
private Integer rows = 10;

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public Integer getPage() {
return page;
}

public void setPage(Integer page) {
this.page = page;
}

public Integer getRows() {
return rows;
}

public void setRows(Integer rows) {
this.rows = rows;
}
}
Loading

0 comments on commit 8803706

Please sign in to comment.